Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Explicit header whitelist

Manav Rathieaccba5f2231
diff --git a/infra/workers/cast-albums/src/index.ts b/infra/workers/cast-albums/src/index.ts
index 8ca3d66bec..f2cef97307 100644
--- a/infra/workers/cast-albums/src/index.ts
+++ b/infra/workers/cast-albums/src/index.ts
@@ -1,18 +1,29 @@
-/** Proxy file and thumbnail requests from the cast web app */
+/** Proxy file and thumbnail requests for the cast web app */
export default {
async fetch(request: Request) {
switch (request.method) {
+ case "OPTIONS":
+ return handleOPTIONS();
case "GET":
return handleGET(request);
- case "OPTIONS":
- return handleOPTIONS(request);
default:
throw new Error(`Unsupported HTTP method ${request.method}`);
}
},
} satisfies ExportedHandler;
+const handleOPTIONS = () => {
+ return new Response("", {
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Methods": "GET, OPTIONS",
+ "Access-Control-Max-Age": "86400",
+ "Access-Control-Allow-Headers": "X-Cast-Access-Token",
+ },
+ });
+};
+
const handleGET = async (request: Request) => {
const url = new URL(request.url);
const castToken =
@@ -32,18 +43,3 @@ const handleGET = async (request: Request) => {
response.headers.set("Access-Control-Allow-Origin", "*");
return response;
};
-
-const handleOPTIONS = (request: Request) => {
- let corsHeaders: Record<string, string> = {
- "Access-Control-Allow-Origin": "*",
- "Access-Control-Allow-Methods": "GET, OPTIONS",
- "Access-Control-Max-Age": "86400",
- };
-
- const acrh = request.headers.get("Access-Control-Request-Headers");
- if (acrh) {
- corsHeaders["Access-Control-Allow-Headers"] = acrh;
- }
-
- return new Response("", { headers: corsHeaders });
-};