直接上代码
const express = require('express');
const app = express()
const hy = require('./routes/hy');
app.all('*', function(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","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
if(req.method=="OPTIONS") res.send(200);/*让options请求快速返回*/
else next();
});
app.use('/', hy);
console.log('server:http://127.0.0.1:3003');
app.listen(3003);
不明白的可以看下面连接下面的数据库查询的可以自行去掉