Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel van Hintum committed Sep 26, 2023
1 parent f6882e4 commit 42a6e6d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function proxyHandle(proxy, options = {}) {
const { pathname } = event.url;

/**
* Do not use hooks on the health endpoint, or the components pages
* Find first matching path
*/
const matchingProxy = Object.keys(proxy).find((proxyPath) => pathname.match(proxyPath));
if (matchingProxy) {
Expand All @@ -20,22 +20,34 @@ export function proxyHandle(proxy, options = {}) {
console.debug(`Proxy: ${proxyTarget}${pathname}`, event.request.headers);
}

/**
* Fetch data from remote server
*/
const resp = await fetch(`${proxyTarget}${pathname}`, {
headers: event.request.headers,
});

/**
* Clean up response headers
*/
const responseHeaders = Object.fromEntries(resp.headers.entries());
delete responseHeaders['content-encoding'];

if (options && options.debug) {
console.debug(`Proxy response headers:`, responseHeaders);
}

/**
* Return response from remote server
*/
return new Response(await resp.text(), {
headers: responseHeaders,
});
}

/**
* Proceed without proxy
*/
const response = await resolve(event);
return response;
};
Expand Down

0 comments on commit 42a6e6d

Please sign in to comment.