Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy with API_URL env var #88

Open
igolka97 opened this issue Dec 30, 2020 · 0 comments
Open

Proxy with API_URL env var #88

igolka97 opened this issue Dec 30, 2020 · 0 comments

Comments

@igolka97
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant