-
Notifications
You must be signed in to change notification settings - Fork 3
/
worker.template.js
52 lines (45 loc) · 1.28 KB
/
worker.template.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
export default {
async fetch(request, env, ctx) {
const { pathname, searchParams } = new URL(request.url);
if (pathname === "/") {
return new Response("Hello");
} else if (pathname === "/default_config.json") {
//
// no cache
return formatResponse(
new Response(JSON.stringify(DEFAULT_CONFIG,null,2)
, {
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
},
}),
);
} else if (pathname === "/meta.json") {
//
// no cache
return formatResponse(
new Response(JSON.stringify(META,null,2)
, {
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
},
}),
);
} else {
return formatResponse(
new Response("Not Found", {
status: 404,
}),
);
}
},
};
function formatResponse(response) {
// add cors header
response.headers.set("Access-Control-Allow-Origin", "*");
response.headers.set("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
response.headers.set("Access-Control-Allow-Headers", "*");
return response;
}