Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
update url path match rule and header filter
Browse files Browse the repository at this point in the history
  • Loading branch information
antergone authored Dec 21, 2023
1 parent 411784e commit d1d6564
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
6 changes: 0 additions & 6 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ const config = {
return [
{
source: "/:_path*",
"has": [
{
"type": "query",
"key": "key",
}
],
destination: "/api/proxy"
},
];
Expand Down
10 changes: 4 additions & 6 deletions src/handle-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const pickHeaders = (headers: Headers, keys: (string | RegExp)[]): Headers => {

const CORS_HEADERS: Record<string, string> = {
"access-control-allow-origin": "*",
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
"access-control-allow-headers": "Content-Type",
"access-control-allow-methods": "*",
"access-control-allow-headers": "*",
};

export default async function handleRequest(request: NextRequest & { nextUrl?: URL }) {
Expand All @@ -40,7 +40,7 @@ export default async function handleRequest(request: NextRequest & { nextUrl?: U
url.searchParams.append(key, value);
});

const headers = pickHeaders(request.headers, ["content-type"]);
const headers = pickHeaders(request.headers, ["content-type", "x-goog-api-client", "x-goog-api-key"]);

const response = await fetch(url, {
body: request.body,
Expand All @@ -50,9 +50,7 @@ export default async function handleRequest(request: NextRequest & { nextUrl?: U

const responseHeaders = {
...CORS_HEADERS,
...Object.fromEntries(
pickHeaders(response.headers, ["content-type"])
),
...Object.fromEntries(response.headers)
};

return new Response(response.body, {
Expand Down

0 comments on commit d1d6564

Please sign in to comment.