app.all('*', function(req, res, next) { //设为指定的域 res.header('Access-Control-Allow-Origin', "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header('Access-Control-Allow-Headers', 'Content-Type'); res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); res.header('Access-Control-Allow-Credentials', true); res.header("X-Powered-By", ' 3.2.1'); next(); });
注意一定要放在应用路由之前,建议位置【var app = express();】后面