nuxt-proxy is a Nuxt 3 module that integrates `http-proxy-middleware` and `h3` to provide HTTP proxying capabilities directly within a Nuxt application. It enables developers to configure declarative proxy rules in `nuxt.config.ts`, facilitating the routing of specific client-side API requests to backend servers. This is commonly used to circumvent CORS restrictions or to unify API endpoints under a single origin. The current stable version is 0.4.1. Releases typically focus on bug fixes, dependency updates (e.g., `h3`, `@nuxt/kit`), and minor feature enhancements such as runtime configuration overrides. Its key differentiator is a streamlined, module-based setup within the Nuxt ecosystem, leveraging Nuxt's Nitro server for efficient middleware handling, offering a more integrated solution than manually setting up a proxy.
npm install nuxt-proxyVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to enable `nuxt-proxy` as a module, configure basic proxy rules in `nuxt.config.ts` including `target`, `pathRewrite`, and `pathFilter`, and show how client-side `useFetch` interacts with the proxied endpoints. It also includes an example of runtime configuration.
Evaluate if `h3.proxyRequest` meets your requirements. If so, consider using it directly in a Nuxt server route (`server/api/**/*.ts`) instead of `nuxt-proxy`.
Ensure you are on `nuxt-proxy@0.4.1` or newer. If issues persist, verify your `pnpm` workspace configuration and check `http-proxy-middleware` for specific ESM caveats.
Consult the documentation on runtime configuration. Typically, environment variables take precedence over `runtimeConfig`, which in turn overrides direct `proxy` configuration in `defineNuxtConfig`.
Carefully review the `http-proxy-middleware` documentation for `pathRewrite` and `pathFilter` syntax and behavior. Test proxy routes thoroughly to ensure they resolve to the expected backend endpoints.
Verify that your `pathFilter` regex or array includes the requested path (`/api/todos`). Ensure `pathRewrite` correctly transforms the path to what the target API expects (e.g., from `/api/todos` to `/todos`). Double-check the `target` URL for accuracy and connectivity.
Add `changeOrigin: true` to your `proxy.options` in `nuxt.config.ts`. If the issue persists, the backend server itself may need configuration to allow requests from the origin the proxy presents, or to include `Access-Control-Allow-Origin` headers for the proxied requests.
Ensure you are using `nuxt-proxy@0.4.1` or newer. If using pnpm, try adding a `.pnpmfile.cjs` or `package.json` `pnpm.patchedDependencies` entry to explicitly patch `http-proxy-middleware` for ESM compatibility, as indicated in `nuxt-proxy`'s changelog, if the issue persists.
Ensure the environment variable is correctly named, typically `NUXT_PROXY_OPTIONS_TARGET` for the root proxy options target. Verify that `runtimeConfig.proxy` is set up in `nuxt.config.ts` to consume these environment variables, and there are no other configurations with higher precedence overriding it.