fix: attempt +1

This commit is contained in:
nate 2026-03-26 12:27:27 +04:00
parent 97b1bb6c9c
commit e34f1938f7
1 changed files with 12 additions and 14 deletions

View File

@ -15,23 +15,21 @@ const SECURITY_HEADERS = {
"Referrer-Policy": "strict-origin-when-cross-origin",
};
const CORS_HEADERS: Record<string, string> = {
"access-control-allow-credentials": "true",
"access-control-allow-methods": "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS",
"access-control-allow-headers": "Content-Type, Authorization",
};
const app = new Elysia()
.onAfterHandle(({ set, request }) => {
Object.assign(set.headers, SECURITY_HEADERS);
.onRequest(({ request, set }) => {
const origin = request.headers.get("origin") || "*";
set.headers["access-control-allow-origin"] = origin;
set.headers["access-control-allow-credentials"] = "true";
set.headers["access-control-allow-methods"] = "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS";
set.headers["access-control-allow-headers"] = "Content-Type, Authorization";
})
.options("/*", ({ set, request }) => {
const origin = request.headers.get("origin") || "*";
set.headers["access-control-allow-origin"] = origin;
set.headers["access-control-allow-credentials"] = "true";
set.headers["access-control-allow-methods"] = "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS";
set.headers["access-control-allow-headers"] = "Content-Type, Authorization";
Object.assign(set.headers, CORS_HEADERS, SECURITY_HEADERS);
if (request.method === "OPTIONS") {
set.status = 204;
return null;
return new Response(null, { status: 204, headers: { ...CORS_HEADERS, ...SECURITY_HEADERS, "access-control-allow-origin": origin } });
}
})
.get("/", () => ({
name: "PingQL API",