Created
June 11, 2022 14:37
-
-
Save riccardogiorato/9bbbafae734d27889f60d140ff5f8d65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /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