美文网首页
node 新项目模块学习20190211

node 新项目模块学习20190211

作者: x8q7 | 来源:发表于2019-02-11 17:41 被阅读0次

    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']
    }));
    
    4.Agenda ---定时任务

    https://www.jianshu.com/p/093f92b98ed9

    相关文章

      网友评论

          本文标题:node 新项目模块学习20190211

          本文链接:https://www.haomeiwen.com/subject/snuqeqtx.html