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');
      });
  • 相关阅读:
    c++ new 堆 栈
    c++ int 负数 补码 隐式类型转换
    python json 序列化
    %pylab ipython 中文
    matplotlib中什么是后端
    IPython 4.0发布:Jupyter和IPython分离后的首个版本
    ipython
    python 类
    python 高级特性
    windows网络模型
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/11066442.html
Copyright © 2011-2022 走看看