nodejs的跨域请求
2018-01-27 本文已影响21人
放风筝的小小马
app.all('*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With');
res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT, OPTIONS');
res.header('X-Powered-By', ' 3.2.1');
if (req.method === 'OPTIONS') {
res.sendStatus(200);
} else {
next();
}
});