Initial: config.saiden.dev worker with KV-backed secrets and files, project/env scoping
This commit is contained in:
+26
@@ -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" },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user