1

I'm trying to proxy requests so that when I call http://localhost:3000/basePath/api it requests http://localhost:8080/api. I'm using the experimental routerules from Nitro to do this:

export default defineNuxtConfig({
    nitro: {
        routeRules: {
            "api/**": { 
                proxy: {
                    to: "http://localhost:8080/**"
                }
            }
        }
    },
    experimental: {
        payloadExtraction: false
    },
    runtimeConfig: {
        public: {
            backUrl: ''
        }
    },
    app: {
        baseURL: "/basePath",
    }
})

The problem is that I want the redirection to be done to http://localhost:8080/api but it's done to http://localhost:8080/basePath/api. I don't understand how to keep the baseURL in my Nuxt3 config but not to have it in the proxy URL when used with a wildcard.

underscore_d
  • 6,309
  • 3
  • 38
  • 64
Xavier FRANCOIS
  • 652
  • 4
  • 15

1 Answers1

1

You can define proxies on the server with proxyRequest and a catch-all route. This will give you all control over the request. That's what route rules seems to do anyway.

Create a file in server/api/[...path].ts

export default defineEventHandler((event) => {
    return proxyRequest(
        event,
        `http://localhost:8080/${event.context.params!.path}`
    )
})
Anoromi
  • 106
  • 2