-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
39 lines (35 loc) · 974 Bytes
/
Copy pathworker.js
File metadata and controls
39 lines (35 loc) · 974 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
32
33
34
35
36
37
38
39
function jsonResponse(payload, status = 200) {
return new Response(JSON.stringify(payload), {
status,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
}
});
}
function optionsResponse() {
return new Response(null, {
status: 204,
headers: {
"access-control-allow-origin": "*",
"access-control-allow-methods": "GET, POST, OPTIONS",
"access-control-allow-headers": "content-type"
}
});
}
export default {
async fetch(request, env) {
const url = new URL(request.url);
const isMusicRoute =
url.pathname === "/api/music/generate" ||
url.pathname === "/api/generate-track" ||
url.pathname === "/api/music/healthz";
if (isMusicRoute) {
if (request.method === "OPTIONS") {
return optionsResponse();
}
return jsonResponse({ error: "music generation has been removed" }, 410);
}
return env.ASSETS.fetch(request);
}
};