Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbeardsley committed Sep 6, 2023
1 parent 9723935 commit adc376d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 11 deletions.
8 changes: 6 additions & 2 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ const moduleExports = {
destination: `https://proxy-us-east.ifixit.com/health-check/proxy-us-east/:path*`,
},
{
source: '/proxy-nextjs-test/:path*',
destination: `/api/php-app/:path*`,
source: '/proxy-nextjs-test',
destination: `/api/php-app/east-proxy`,
},
{
source: '/proxy-edge-test',
destination: `/api/php-app/edge-east-proxy`,
},
],
};
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@tanstack/react-query": "4.14.5",
"@types/http-proxy": "1.17.11",
"@vercel/analytics": "1.0.1",
"agentkeepalive": "4.5.0",
"algoliasearch": "4.13.1",
"cookie": "0.5.0",
"dayjs": "1.10.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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 (
Expand All @@ -16,6 +18,7 @@ const handler: NextApiHandler = async (

export const config = {
api: {
bodyParser: false,
externalResolver: true,
},
};
Expand Down
73 changes: 73 additions & 0 deletions frontend/pages/api/php-app/edge-east-proxy.ts
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

Check failure on line 35 in frontend/pages/api/php-app/edge-east-proxy.ts

View workflow job for this annotation

GitHub Actions / linter

'res' is defined but never used. Allowed unused args must match /^_/u
) => {
// @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;
15 changes: 6 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit adc376d

Please sign in to comment.