const express = require(‘express‘);
const app = express();
//设置允许跨域访问该服务.
app.all(‘*‘, function (req, res, next) {
res.header(‘Access-Control-Allow-Origin‘, ‘*‘);
//Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
res.header(‘Access-Control-Allow-Headers‘, ‘Content-Type‘);
res.header(‘Access-Control-Allow-Methods‘, ‘*‘);
res.header(‘Content-Type‘, ‘application/json;charset=utf-8‘);
next();
});
app.get(‘/hello‘, function (req, res) {
res.json({})
});
————————————————
版权声明:本文为CSDN博主「ffiing」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_34545192/article/details/80177362
原文地址:https://www.cnblogs.com/liuhao-web/p/11507762.html
时间: 2024-11-01 20:25:50