slate/common/middleware.js

18 lines
390 B
JavaScript
Raw Normal View History

2020-02-19 09:30:47 +03:00
export const CORS = async (req, res, next) => {
2020-06-19 06:57:57 +03:00
res.header("Access-Control-Allow-Origin", "*");
2020-02-19 09:30:47 +03:00
res.header(
2020-06-19 06:57:57 +03:00
"Access-Control-Allow-Methods",
"GET, POST, PATCH, PUT, DELETE, OPTIONS"
2020-02-19 09:30:47 +03:00
);
res.header(
2020-06-19 06:57:57 +03:00
"Access-Control-Allow-Headers",
"Origin, Accept, Content-Type, Authorization"
2020-02-19 09:30:47 +03:00
);
2020-06-19 06:57:57 +03:00
if (req.method === "OPTIONS") {
2020-02-19 09:30:47 +03:00
return res.status(200).end();
}
next();
};