Nuxt 3 with Docker and Backend
I have a REST that works fine in Dev and Prod mode with SPA Vue 3.
As a frontend for my application, I have chosen Nuxt 3 and am getting the following problem:
1. On the page i make a call to my API:
And get Error:
fetch failed ()
if i reload browser page or if i trying to access the page directly. But if i switch to another route and come back, the call above works and I get the data.
2. I can solve this problem if instead of localhost, I specify the name of my backend container:
But now if I switch to another route and come back I get this error:
I use NGINX as reverse proxy & CORS is enabled on my backend.
In my dashboard Vue 3 works fine with my API. But in Nuxt 3 i get the problems described above. Please tell me what am I doing wrong?9 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Can you help me pls a little more with about creating a docker network? in docker-compose do i need to create a network and declare it in containers?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Ok, thank you anyway!
i find a solution
for anyone who face the same problem case, i use
useAsyncData
and for baseUrl - process.server ? runtimeConfig.public.BASE_API_URL : runtimeConfig.public.BASE_API_BROWSER_URL
, where browser url is localhost and base url is backend docker container name
now everything works fine, there is no hydration missmatch warnings and SSR works fineUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
yes sure
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Many thanks!
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View