next-http-proxy-middleware icon indicating copy to clipboard operation
next-http-proxy-middleware copied to clipboard

Additional headers doesn't write to request

Open 3nodecz opened this issue 4 years ago • 1 comments

I am experiencing problem that I am not able to add any custom headers. I have made a quick look on your code and I don't see any action with headers on proxy request ...

3nodecz avatar Feb 20 '21 08:02 3nodecz

Hi @3nodecz, You can add custom headers through the http-proxy setting.

  • ref: https://www.npmjs.com/package/http-proxy#options

Please refer to the source code below 😀

// Custom headers examples
export default (req: NextApiRequest, res: NextApiResponse) => (
  isDevelopment
    ? httpProxyMiddleware(req, res, {
     ...
      headers: {
        HELLO: 'Hello :)', // <- You can add custom headers
      },
    })
    : res.status(404).send(null)
);

stegano avatar Feb 26 '21 13:02 stegano