SSR: Axios request fails with 404 when using a proxy
See original GitHub issueI’m using Laravel Lumen for the backend, which is on a different domain, so I have to use a proxy to be able to share the cross-origin resource.
Everything works fine on the client-side, but when enabling universal mode and trying to get a prerendered site with the first request products are not rendered because Axios request fails with status code 404.
After enabling Axios debugging I have noticed that ‘api’ string is still in the requested URL, but it shouldn’t be, because of the pathRewrite rule:
proxy: {
'/api': {
target: process.env.API_URL,
pathRewrite: {
'^/api': '/'
},
changeOrigin: true
}
}
When modifying code like this (removed ‘api’ in the request path), Axios request works, but then of course doesn’t on the client.
What can I do to make the request work on the client and server side?
Nuxt.js v2.12.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Vue How to fix 404 error when using nuxt proxy and nuxt axios
In my vue -app I'm using the @nuxtjs/proxy together with @nuxtjs/axios but for some reason I don't know, I always get an Request...
Read more >[axioserror: request failed with status code 404] - You.com
IMHO 404 means that the endpoint that you are looking for does not exist. In some cases, it also means that the method...
Read more >Axios 404 Not Found - Azienda Roberto e Nicola Ercolani
SSR: Axios request fails with 404 when using a proxy #464. 404 Not Found error messages are frequently customized by individual websites. axios...
Read more >Problem with Axios/Proxy : r/Nuxt - Reddit
Looking at the docs, you may need to set the 'prefix' option while using the proxy. https://axios.nuxtjs.org/options/#baseurl.
Read more >Have a Axios error "Request failed with status code 404" in ...
Hi anyone, i am using nuxtjs for my project. But i have a problem, on mode ssr(server side render) when run project is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe it’s because the API_URL env variable is overriding the baseURL parameter. IDK if that’s what you want here. Try using a different name.
try to following this code bellow:
nuxt.config.js