I have nuxt frontend and api backend on 1337 port.
I'm trying to proxy http://*nuxtapp*/api/* requests to http://localhost:1337/
Example http://*nuxtapp*/api/products to http://localhost:1337/products
When I'm using API_URL env var, as was mentioned here or here (as 'already practiced solution') then my requests are proxies to http://localhost:1337/api/products instead http://localhost:1337/products
But if I change var name to something another, like API_TARGET then it works as expected.
nuxt.config.js:
axios: {
proxy: true,
},
proxy: {
'/api/': {
target: process.env.API_URL || 'http://localhost:1337',
pathRewrite: { '^/api/': '' },
changeOrigin: true,
},
},
I already looked around this problem:
- when I set
config.axios.baseUrl then config.proxy stop working at all.
- from axios official docs:
Environment variable API_URL can be used to override baseURL
- from axios official docs:
WARNING: baseURL and proxy cannot be used at the same time
Okay, if I understand, using baseURL or API_URL totally disabling proxy feature (or, pathRewrite feature, like in this case) and I have to use any another env var. But why it works in mentioned cases (links on top of this letter)? Or, what I exactly need to do in this case?
I have nuxt frontend and api backend on 1337 port.
I'm trying to proxy
http://*nuxtapp*/api/*requests tohttp://localhost:1337/Example
http://*nuxtapp*/api/productstohttp://localhost:1337/productsWhen I'm using
API_URLenv var, as was mentioned here or here (as 'already practiced solution') then my requests are proxies tohttp://localhost:1337/api/productsinsteadhttp://localhost:1337/productsBut if I change var name to something another, like
API_TARGETthen it works as expected.nuxt.config.js:
I already looked around this problem:
config.axios.baseUrlthenconfig.proxystop working at all.Environment variable API_URL can be used to override baseURLWARNING: baseURL and proxy cannot be used at the same timeOkay, if I understand, using
baseURLorAPI_URLtotally disablingproxyfeature (or,pathRewritefeature, like in this case) and I have to use any another env var. But why it works in mentioned cases (links on top of this letter)? Or, what I exactly need to do in this case?