express解决跨域
2020-09-04 本文已影响0人
一个健康马
const express = require('express');
const app = express()
//设置允许跨域访问该服务.
app.all('', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods', '*');
res.header('Content-Type', 'application/json;charset=utf-8');
next();
});