app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Origin-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE');
return res.status(200).json({});
}
// if you don't call next() node api flow will stop this
// because app.use is middleware, it will do something after action, like pipeline
// So Don't call next() just like stop water flow here.
// So that it will cause api pedding, and then timeout.
next();
});