nuxt3 dev proxy

796 阅读1分钟

server / client 可用

   export default defineNuxtConfig({  
        nitro: {
            devProxy: {
                "/devApi": {
                    target:"your url",
                    changeOrigin: true,
                    prependPath: true,
                }
            }
        },
    })

vite 项的相关配置,仅在client可用

  vite: {
    server: {
      proxy: {
        "/api": {
          target: "***",
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  },

nitro 配置文档 nitro.unjs.io/config

devProxy

Proxy configuration for development server.

You can use this option to override development server routes and proxy-pass requests.

{
  devProxy: {
    '/proxy/test': 'http://localhost:3001',
    '/proxy/example': { target: 'https://example.com', changeOrigin: true }
  }
}

See github.com/http-party/… for all available target options.