-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (39 loc) · 1.14 KB
/
Copy pathindex.ts
File metadata and controls
45 lines (39 loc) · 1.14 KB
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
/**
* Public Edge Function: server_status
*
* Returns a browser-safe status snapshot for the login screen.
* No EDGE_API_TOKEN required.
*/
import { getPublicServerStatusSnapshot } from "../_shared/server_status.ts";
import { traced } from "../_shared/weave.ts";
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Max-Age": "86400",
};
function corsJsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: {
...corsHeaders,
"Content-Type": "application/json",
"Cache-Control": "no-store",
},
});
}
Deno.serve(traced("server_status", async (req) => {
if (req.method === "OPTIONS") {
return new Response(null, { status: 204, headers: corsHeaders });
}
if (req.method !== "GET" && req.method !== "POST") {
return corsJsonResponse(
{ success: false, error: "Method not allowed" },
405,
);
}
return corsJsonResponse({
success: true,
...getPublicServerStatusSnapshot(),
});
}));