mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-12 08:08:46 +08:00
Refactoring the backend
This commit is contained in:
15
backend/src/middleware/cors.ts
Normal file
15
backend/src/middleware/cors.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
export const cors = () => {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, Cookie");
|
||||
res.header("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
if (req.method === "OPTIONS") {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
next();
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user