node配置跨域问题

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()
})

 

posted @ 2020-06-16 15:30  心之所指,行之所至  阅读(190)  评论(0)    收藏  举报