node 新增模块学习
1. compression--用于请求文件的压缩
var compression = require('compression');
app.use(compression());
2.helmet--防护包含点击劫持、xss、嗅探攻击...
https://blog.csdn.net/momDIY/article/details/76944293
var express = require('express')
var helmet = require('helmet')
var app = express();
//使用helmet全部功能
app.use(helmet());
//单独使用某一功能
app.use(helmet.noCache());
3.cors---跨域的问题
//设置跨域访问
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-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
var cors = require('cors');
app.use(cors({
origin:['http://localhost:8083'],
methods:['GET','POST'],
alloweHeaders:['Conten-Type', 'Authorization']
}));
网友评论