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

Vite dev proxy doesn't work after upgrade to v3.0.0 #15503

Closed
ppodds opened this issue Nov 17, 2022 · 2 comments
Closed

Vite dev proxy doesn't work after upgrade to v3.0.0 #15503

ppodds opened this issue Nov 17, 2022 · 2 comments

Comments

@ppodds
Copy link

ppodds commented Nov 17, 2022

Environment


  • Operating System: Linux
  • Node Version: v16.18.0
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: pnpm@7.16.1
  • Builder: vite
  • User Config: vite
  • Runtime Modules: -
  • Build Modules: -

Reproduction

nuxt.config.ts

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  vite: {
    server: {
      proxy: {
        "/api": {
          target: "https://www.google.com/",
          changeOrigin: true,
        }
      }
    }
  }
})

Describe the bug

Vite dev server proxy doesn't work, but it works correctly in v3.0.0-rc.8.

Additional context

After testing multiple versions of nuxt, I found this bug was introduced after rc.12.
It might be related to nuxt/framework#7989 or the route rules update. I hope it is useful to you.

Logs

No response

@ppodds
Copy link
Author

ppodds commented Nov 17, 2022

Nuxt rewrite request url like this:

/api => /__url/api

Vite server can't handle /__url prefix automatically, so the proxy setting not match.

Workaround

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  vite: {
    server: {
      proxy: {
        "/__url/api": {
          target: "https://www.google.com/",
          changeOrigin: true,
        }
      }
    }
  }
})

@ninebolt6
Copy link

use nitro.devProxy instead. https://nitro.unjs.io/config#devproxy

#15195

@ppodds ppodds closed this as completed Nov 19, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants