在飞行前解决角色没有连接

时间:2013-08-21 03:25:04

标签: cors restify preflight

我们无法通过飞行前的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);
}); 

1 个答案:

答案 0 :(得分:0)

试过这个?

server.use(restify.CORS());