fix: attempt +1
This commit is contained in:
parent
97b1bb6c9c
commit
e34f1938f7
|
|
@ -15,23 +15,21 @@ const SECURITY_HEADERS = {
|
||||||
"Referrer-Policy": "strict-origin-when-cross-origin",
|
"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()
|
const app = new Elysia()
|
||||||
.onAfterHandle(({ set, request }) => {
|
.onRequest(({ request, set }) => {
|
||||||
Object.assign(set.headers, SECURITY_HEADERS);
|
|
||||||
const origin = request.headers.get("origin") || "*";
|
const origin = request.headers.get("origin") || "*";
|
||||||
set.headers["access-control-allow-origin"] = origin;
|
set.headers["access-control-allow-origin"] = origin;
|
||||||
set.headers["access-control-allow-credentials"] = "true";
|
Object.assign(set.headers, CORS_HEADERS, SECURITY_HEADERS);
|
||||||
set.headers["access-control-allow-methods"] = "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS";
|
if (request.method === "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";
|
|
||||||
set.status = 204;
|
set.status = 204;
|
||||||
return null;
|
return new Response(null, { status: 204, headers: { ...CORS_HEADERS, ...SECURITY_HEADERS, "access-control-allow-origin": origin } });
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.get("/", () => ({
|
.get("/", () => ({
|
||||||
name: "PingQL API",
|
name: "PingQL API",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue