mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-30 22:13:47 +03:00
32 lines
669 B
JavaScript
32 lines
669 B
JavaScript
export const init = (middleware) => {
|
|
return (req, res) =>
|
|
new Promise((resolve, reject) => {
|
|
middleware(req, res, (result) => {
|
|
if (result instanceof Error) {
|
|
return reject(result);
|
|
}
|
|
return resolve(result);
|
|
});
|
|
});
|
|
};
|
|
|
|
export const CORS = async (req, res, next) => {
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
res.header(
|
|
"Access-Control-Allow-Methods",
|
|
"GET, POST, PATCH, PUT, DELETE, OPTIONS"
|
|
);
|
|
|
|
res.header(
|
|
"Access-Control-Allow-Headers",
|
|
"Origin, Accept, Content-Type, Authorization"
|
|
);
|
|
|
|
if (req.method === "OPTIONS") {
|
|
return res.status(200).end();
|
|
}
|
|
|
|
next();
|
|
};
|