node配置跨域问题

时间:2020-06-16 16:27:13   收藏:0   阅读:54
const express = require("express");

const app = express();

app.all("*", (req, res, next) => {
    res.header("Content-Type", "text/plain;charset=utf-8")
    //设置允许跨域的域名,*代表允许任意域名跨域
    res.header("Access-Control-Allow-Origin", "*")
    //跨域允许的请求方式
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
    //允许的header类型
    res.header("Access-Control-Allow-Headers", "x-requested-with,content-type")
    //设置响应头信息
    res.header("X-Powered-By", ‘ 3.2.1‘)
    next()
})

 

原文:https://www.cnblogs.com/wangyisu/p/13141199.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!