参考:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS
// **** 跨域 *(废弃)***
// app.all('*', function (req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With, t-data");
// res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
// res.header("X-Powered-By", ' 3.2.1')
// res.header("Content-Type", "application/json;charset=utf-8");
// // console.log("aaaa");
// next();
// });
// **** 跨域 ****
const cors = require('cors');
app.use(
cors({
origin: [
'http://localhost:8080',
'http://106.13.51.5:8080' // 允许的域名
],
credentials: true, // 允许cookie
exposedHeaders: "t-data" // 扩展表头
}),
);