zoukankan      html  css  js  c++  java
  • nodejs使用express模块使用过滤器添加跨越访问控制

    1. npm install express    安装express模块

    2. 使用express模块添加filter
      const express = require('express');
      const app = express();

      let filter = (req, res, next) => {
        res.setHeader("Access-Control-Allow-Origin", "*");  //添加跨越访问控制
        next();
      }
      app.use(filter);
     
      //需要npm install body-parser 安装该模块
      const bodyParser = require('body-parser');
      // application/x-www-form-urlencoded
      app.use(bodyParser.urlencoded({ extended: false }));
      // application/json
      app.use(bodyParser.json());
     
      app.post('*', (req, res) => {
        var params = req.body  //body-parser模块提供的body获取post请求体内容
        console.log(params)
        res.send('post ok')
      })

      app.listen(9090, function () {  //监听9090端口
        console.log('server start');
      });
  • 相关阅读:
    hudson搭建经验总结(二)
    CodePen最佳实例分享
    hudson搭建经验总结
    资料文件夹管理系统
    ueditor+word图片上传
    asp.net上传大文件
    UEditor粘贴word
    大文件上传组件
    文件资源管理系统
    ueditor+复制word图片粘贴上传
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/11066442.html
Copyright © 2011-2022 走看看