gpt4 book ai didi

cors - 修复 cors 飞行前未连接

转载 作者:行者123 更新时间:2023-12-04 17:05:35 28 4
gpt4 key购买 nike

我们无法在飞行前恢复使用 cors:任何帮助都非常感谢

==========错误==========================

About to connect() to localhost port 3000 (#0)
* Trying ::1...
* Adding handle: conn: 0x9d834e8
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x9d834e8) send_pipe: 1, recv_pipe: 0
* Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)

======== curl ============================
# **** note **** is local....
curl -i -X OPTIONS -H "Access-Control-Request-Method: POST" http://****:3000/api/account
-d '{"accountname":"test","organization":"test"}' -H "Content-Type: application/json"
-H "Origin: http://****:8000" -H "Access-Control-Request-Headers: X-Requested-With"
--verbose

========== 重新化代码 ==================
var restify = require('restify');  
var server = restify.createServer();

var preflight = require('se7ensky-restify-preflight');
preflight(server);

server.post('/api/account', function(req,res,next) {
console.log("inside account post function");
console.log("req body " + JSON.stringify(req.body));
if (!req.body) {
response.statusCode = 400;
return res.send("Missing or Invalid Params");
} else {
res.send('hello ');
}
});

server.listen(3000, function() {
console.log('%s listening at %s', server.name, server.url);
});

最佳答案

试过这个吗?

server.use(restify.CORS());

关于cors - 修复 cors 飞行前未连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18348371/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com