mirror of
https://github.com/Feuerhamster/mailform.git
synced 2025-04-28 17:56:53 +02:00
Fix CORS and preflighted requests
This commit is contained in:
parent
1c3ece87fd
commit
3108100c18
1 changed files with 5 additions and 0 deletions
|
@ -23,6 +23,7 @@ router.use("/:target", async (req: Request, res: Response, next: NextFunction) =
|
|||
// CORS
|
||||
res.setHeader("Access-Control-Allow-Origin", target.origin);
|
||||
res.setHeader("Access-Control-Allow-Method", "POST");
|
||||
res.setHeader("Access-Control-Allow-Headers", "*");
|
||||
|
||||
// Check origin
|
||||
if(target.origin !== req.header("origin")) {
|
||||
|
@ -38,6 +39,10 @@ router.use("/:target", async (req: Request, res: Response, next: NextFunction) =
|
|||
}
|
||||
}
|
||||
|
||||
if(req.method === "OPTIONS") {
|
||||
return res.status(200).end();
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue