mirror of
https://github.com/zhigang1992/telert.git
synced 2026-01-12 08:24:41 +08:00
feat: enhance CORS middleware with preflight request handling
This commit is contained in:
13
src/index.ts
13
src/index.ts
@@ -129,8 +129,19 @@ router.post("/t/:webhookId/map", async (context) => {
|
||||
context.res.body = { ok: true };
|
||||
});
|
||||
|
||||
const cors: Middleware = async ({ res }, next) => {
|
||||
const cors: Middleware = async ({ req, res }, next) => {
|
||||
// Set CORS headers
|
||||
res.headers.set("access-control-allow-origin", "*");
|
||||
res.headers.set("access-control-allow-methods", "GET, POST, OPTIONS");
|
||||
res.headers.set("access-control-allow-headers", "Content-Type");
|
||||
res.headers.set("access-control-max-age", "86400");
|
||||
|
||||
// Handle preflight requests
|
||||
if (req.method === "OPTIONS") {
|
||||
res.status = 204;
|
||||
return;
|
||||
}
|
||||
|
||||
await next();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user