mirror of
https://github.com/sr229/kuru-kuru.git
synced 2024-09-20 04:10:33 +00:00
feat: Added middleware for handling CORS
Added middleware for handling CORS and setting necessary headers
This commit is contained in:
parent
dd9b86af93
commit
3eaa783c15
2 changed files with 25 additions and 2 deletions
|
@ -4,7 +4,8 @@
|
|||
|
||||
import * as $0 from "./routes/_404.tsx";
|
||||
import * as $1 from "./routes/_app.tsx";
|
||||
import * as $2 from "./routes/index.tsx";
|
||||
import * as $2 from "./routes/_middleware.ts";
|
||||
import * as $3 from "./routes/index.tsx";
|
||||
import * as $$0 from "./islands/CounterCard.tsx";
|
||||
import * as $$1 from "./islands/MarkdownContent.tsx";
|
||||
|
||||
|
@ -12,7 +13,8 @@ const manifest = {
|
|||
routes: {
|
||||
"./routes/_404.tsx": $0,
|
||||
"./routes/_app.tsx": $1,
|
||||
"./routes/index.tsx": $2,
|
||||
"./routes/_middleware.ts": $2,
|
||||
"./routes/index.tsx": $3,
|
||||
},
|
||||
islands: {
|
||||
"./islands/CounterCard.tsx": $$0,
|
||||
|
|
21
routes/_middleware.ts
Normal file
21
routes/_middleware.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
|
||||
const origin = req.headers.get("Origin") || "*";
|
||||
const resp = await ctx.next();
|
||||
const headers = resp.headers;
|
||||
|
||||
headers.set("Access-Control-Allow-Origin", origin);
|
||||
headers.set("Access-Control-Allow-Credentials", "true");
|
||||
headers.set("Cache-Control", "public, max-age=14400, stale-while-revalidate=86400");
|
||||
headers.set(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With",
|
||||
);
|
||||
headers.set(
|
||||
"Access-Control-Allow-Methods",
|
||||
"POST, OPTIONS, GET",
|
||||
);
|
||||
|
||||
return resp;
|
||||
}
|
Loading…
Reference in a new issue