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 and making fetch async), 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
- Reactions:2
- Comments:10
Top Results From Across the Web
SSR: Axios request fails with 404 when using a proxy · Issue ...
I'm using Laravel Lumen for the backend, which is on a different domain, so I have to use a proxy to be able...
Read more >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 >Problem with Axios/Proxy : r/Nuxt - Reddit
I am using the nuxtjs/axios and nuxtjs/proxy modules with the ... (which fails with 404) instead of api.example.com/product/getProduct.
Read more >[Solved]-Proxy not hitting in Nuxt Axios causing CORS-nuxt.js
while proxying you have to call it below way async fetch() { const data = await this.$axios.$get( '/listingapi/api/export', { credentials: true, ...
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 Free
Top 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
@bagaskarala .env variable named API_URL was causing me problems since it overrides baseURL config of ‘@nuxtjs/axios’. I prepared a demo project when I was looking for help and updated it with a “solution”: https://github.com/juretopolak/nuxt-axios-proxy-ssr-demo
@xlanex6 if you also named your .env variable API_URL maybe you are facing the same problem.
i’m also facing this issue, then i’ve resolved it. To call backend api, set this env
API_URL: http://backend.com
. then i use this setting:i proxied request
HOST/api
to actual backend url, it will work on server and client slide request. note: HOST can be your localhost (dev) or your frontend url (production)