【问题标题】:restify cors pre-flight not connectingrestify cors 飞行前未连接
【发布时间】:2013-08-23 06:58:20
【问题描述】:

我们无法在飞行前与 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)

========卷曲============================

# **** 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);
}); 

【问题讨论】:

    标签: cors restify preflight


    【解决方案1】:

    试过了吗?

    server.use(restify.CORS());
    

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 2021-08-11
      • 2019-05-23
      • 2016-06-28
      • 2016-07-08
      • 2013-09-22
      • 2017-10-19
      • 2016-09-24
      • 2019-06-09
      相关资源
      最近更新 更多