-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9723935
commit adc376d
Showing
5 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'; | ||
import httpProxy from 'http-proxy'; | ||
import { HttpsAgent } from 'agentkeepalive'; | ||
const proxy = httpProxy.createProxyServer({ | ||
secure: true, | ||
changeOrigin: true, | ||
agent: new HttpsAgent(), | ||
}); | ||
const handler: NextApiHandler = async ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => { | ||
const dest = `https://proxy-us-east.ifixit.com/health-check${req.url}`; | ||
proxy.web(req, res, { target: dest }); | ||
}; | ||
export const config = { | ||
api: { | ||
bodyParser: false, | ||
externalResolver: true, | ||
}, | ||
}; | ||
export default handler; | ||
*/ | ||
|
||
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler: NextApiHandler = async ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => { | ||
// @ts-ignore | ||
const headers = getFetchHeaders( | ||
Array.from(req.headers.entries()) as [string, string][] | ||
); | ||
//headers.push(['host', 'proxy-us-east.ifixit.com']); | ||
const fetchOpts = { | ||
method: req.method, | ||
body: req.body, | ||
keepalive: true, | ||
headers: headers, | ||
}; | ||
console.log(fetchOpts); | ||
const dest = `https://proxy-us-east.ifixit.com/health-check${req.url}`; | ||
return fetch(dest, fetchOpts); | ||
}; | ||
|
||
function getFetchHeaders(reqHeaders: Generator<string, void, void>) { | ||
const result: Array<[string, string]> = []; | ||
// @ts-ignore | ||
for (const [key, value] of reqHeaders) { | ||
if (key === 'host') { | ||
continue; | ||
} | ||
result.push([key, value]); | ||
} | ||
return result; | ||
} | ||
|
||
export const config = { | ||
api: { | ||
externalResolver: true, | ||
bodyParser: false, | ||
}, | ||
runtime: 'edge', | ||
}; | ||
|
||
export default handler; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.