Package Exports
- next-http-proxy-middleware
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (next-http-proxy-middleware) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Next.js HTTP Proxy Middleware
HTTP Proxy middleware available in API Middleware provided by Next.js.
Installation
The easiest way to install next-http-proxy-middleware is with npm.
npm install next-http-proxy-middleware
Alternately, download the source.
git clone https://github.com/stegano/next-http-proxy-middleware.git
Features
This middleware is implemented using the http-proxy library. You can use the existing options provided by http-proxy. And you can rewrite the api path using pathRewrite, an additional option provided by this middleware.
Example
Refer to the following for how to use Nextjs API Middleware
// pages/[...all].ts
...
export default (req: NextApiRequest, res: NextApiResponse) => (
isDevelopment
? httpProxyMiddleware(req, res, {
target: 'https://www.example.com',
pathRewrite: {
'^/api/new': '/v2', // `/api/new/test` -> `/v2/test`
'^/api': '', // `/api/test` -> `/test`
},
})
: res.status(404).send(null)
);