节点:CORS偶尔失败

我有一个托pipe在heroku上的服务器的节点应用程序。 我所有的请求都是成功的,直到我发送了10或15个。然后我开始接收CORS错误。 任何想法为什么这可能发生?

试一试。 http://danielrasmuson.github.io/

这是我的'CORS启用代码'。 我正在尝试几件事。

var app = express(); app.use(cors()); app.all('/*', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); next(); }); app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); 

我不知道是不是太晚,但也许这可以帮助:我有这个代码相同的问题:(偶尔我得到Cors错误与503 heroku错误)

 router.post('/create', function (req, res, next) { password(req.body.user_password).hash(function (error, hash) { if (error) throw new Error('Something went wrong!' + error) console.log(req.body); req.body.user_password = hash; User.create(req.body, function (err, post) { if (err) return next(err); console.log(post); res.json(post); }); }); }); 

当我将其更改为:

 router.post('/create', function (req, res, next) { password(req.body.user_password).hash(function (error, hash) { if (error) { throw new Error('Something went wrong!' + error); } else { req.body.user_password = hash; User.create(req.body, function (err, post) { if (err) { throw new Error('Something went wrong!' + err); } else { res.json(post); } }); } }); }); 

没有更多的失败的代码和Cors偶尔。

最后这似乎是节点应用程序的问题,而不是heroku。

欢呼Blazej