-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse-proxy.js
More file actions
31 lines (24 loc) · 957 Bytes
/
reverse-proxy.js
File metadata and controls
31 lines (24 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Configuration
const PROXY_TARGET = 'new.polygon.technology';
const PROXY_ROUTES = ['/', '/about', '/launch/build-with-oms', '/polygon-pos', '/trails'];
export default {
async fetch(request) {
const url = new URL(request.url);
console.log(url);
const shouldProxy = PROXY_ROUTES.some(route =>
url.pathname === route || url.pathname.startsWith(route + '/')
);
if (shouldProxy) {
console.log(`Proxy to: ${PROXY_TARGET}${url.pathname}`);
const response = await fetch(`https://${PROXY_TARGET}${url.pathname}${url.search}`, {
method: request.method,
headers: request.headers,
body: request.body,
});
const newResponse = new Response(response.body, response);
return newResponse;
}
// All other routes: pass through to original domain
return fetch(request);
}
};