Unexpected response code: 502 error when using socket.io with AppFog-Collection of common programming errors
When the user opens http://sync.aws.af.cm/, the Google Chrome JavaScript Console shows (within a few seconds):
Unexpected response code: 502 error
The app should remember the contents of the text area even after the user refreshes the page. The app works locally, but not when I upload it to AppFog, and I suspect the problem is the 502 error.
Do you know what might cause this error in this case?
What I’ve tried
I tried changing the script src=
path in my client from /socket.io/socket.io.js
to node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js
as described here, but it did not help.
I also tried serving the app at Heroku instead of AppFog, but in that case I kept running into the issue described here even though I specified socket.io version 0.9.6.
I’ve also looked at the following questions, but the comments so far don’t seem to help me.
socket.io creating 502 Bad Gateway on connect / websocket invalid
Socket.IO node.js websocket connection invalid port 8081
socket.io with node.js not working as expected
Relevant server code
Here is the relevant server code:
var server = http.createServer(function (req, res) {
...
});
var io = require('socket.io').listen(server);
// Define events that can be triggered by the client
io.sockets.on('connection', function (socket) {
socket.on('setServerVariable', function (value) {
...
});
...
});
server.listen(process.env.VCAPP_APP_PORT || 3000);
Relevant client code
window.onload = function () {
...
var socket = io.connect(window.location.hostname);
socket.emit('getServerVariable');
...
};
...
$ af logs sync
====> /logs/stdout.log