Skip to content

Instantly share code, notes, and snippets.

@riccardogiorato
Created June 11, 2022 14:37
Show Gist options
  • Save riccardogiorato/9bbbafae734d27889f60d140ff5f8d65 to your computer and use it in GitHub Desktop.
Save riccardogiorato/9bbbafae734d27889f60d140ff5f8d65 to your computer and use it in GitHub Desktop.
// /api/reverse-proxy/[...all].ts
import { NextApiRequest, NextApiResponse } from "next/types";
import httpProxyMiddleware from "next-http-proxy-middleware";
export const config = {
api: {
externalResolver: true,
},
};
export default (req: NextApiRequest, res: NextApiResponse) =>
httpProxyMiddleware(req, res, {
// You can use the `http-proxy` option
target: "https://www.tesla.com",
pathRewrite: [
{
// put here the same path of the folder and file from the nextjs APIs here
patternStr: "^/api/reverse-proxy",
replaceStr: "",
},
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment