mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-12 08:08:46 +08:00
16 lines
531 B
TypeScript
16 lines
531 B
TypeScript
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();
|
|
};
|
|
};
|