-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.js
More file actions
24 lines (21 loc) · 773 Bytes
/
Copy pathworker.js
File metadata and controls
24 lines (21 loc) · 773 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
// Proxy /api/* requests to the Django backend through Cloudflare Tunnel.
const API_ORIGIN = "https://api.gcers.org";
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname.startsWith("/api/")) {
const target = new URL(url.pathname + url.search, API_ORIGIN);
return fetch(target, {
method: request.method,
headers: request.headers,
body:
request.method === "GET" || request.method === "HEAD"
? undefined
: await request.arrayBuffer(),
});
}
// Non-API paths are handled by static assets (run_worker_first only
// routes /api/* here); fall back to a plain 404 just in case.
return new Response("Not found", { status: 404 });
},
};