教务管理系统(node+express+mysql)
- 安装 express
npm install express -g
2. 创建工程
express 你的工程名(墙裂建议使用英文)
3. 安装依赖
npm install
// conf/db.js // MySQL数据库联接配置 module.exports = { mysql: { host: '127.0.0.1', // ip user: 'root', // 用户名 password: '123456', // 数据库密码 database:'test1', // 你数据库的名称 port: 3306 // 端口 } };
9. 在路由中进行跨域配置
app.use('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', req.headers.origin);//注意这里不能使用 *
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header("X-Powered-By",' 3.2.1');
res.header('Access-Control-Allow-Credentials', true); // 允许服务器端发送Cookie数据
res.header("Content-Type", "application/json;charset=utf-8");
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');//设置方法
if (req.method == 'OPTIONS') {
res.sendStatus(200); // 在正常的请求之前,会发送一个验证,是否可以请求。
}
else {
next();
}
});

浙公网安备 33010602011771号