32 lines
698 B
JavaScript
32 lines
698 B
JavaScript
import Cors from 'cors';
|
|
|
|
function initMiddleware(middleware)
|
|
{
|
|
console.log("CORS initMiddleware !!!!");
|
|
|
|
return (req, res) =>
|
|
new Promise((resolve, reject) =>
|
|
{
|
|
middleware(req, res, (result) =>
|
|
{
|
|
if (result instanceof Error)
|
|
{
|
|
return reject(result);
|
|
}
|
|
|
|
return resolve(result);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Initialize the cors middleware
|
|
const cors = initMiddleware(
|
|
// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
|
|
Cors({
|
|
origin: ["http://localhost:3000", "https://lk-evo.quickcode.ru"],
|
|
// Only allow requests with GET, POST and OPTIONS
|
|
methods: ['GET', 'POST', 'OPTIONS'],
|
|
})
|
|
)
|
|
|
|
export { cors }; |