这是我的服务器代码:
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 3001));
var server = app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
var io = require('socket.io').listen(server);
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
io.set('origins', 'https://desolate-bayou-62509.herokuapp.com/');
io.sockets.on('connection', function (socket) {
socket.on('message', function () {
console.log("Incoming request");
}
});
});
我已在Heroku中部署了此代码。从localhost访问时,这可以正常工作。我已经在Heroku中部署了前端PHP代码。现在,这个Node js代码返回400错误代码。