Initial: config.saiden.dev worker with KV-backed secrets and files, project/env scoping

This commit is contained in:
marauder-actual
2026-06-10 16:59:18 +02:00
commit 339f68de4b
10 changed files with 3495 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import type { Env } from "./types";
export function authenticate(request: Request, env: Env): Response | null {
const header = request.headers.get("Authorization");
if (!header) {
return json(401, { error: "Missing Authorization header" });
}
const [scheme, token] = header.split(" ", 2);
if (scheme !== "Bearer" || !token) {
return json(401, { error: "Invalid Authorization format. Use: Bearer <key>" });
}
if (token !== env.API_KEY) {
return json(403, { error: "Invalid API key" });
}
return null; // authenticated
}
export function json(status: number, body: unknown): Response {
return new Response(JSON.stringify(body), {
status,
headers: { "Content-Type": "application/json" },
});
}