I'm new to node.js and I'm trying to create a chat app following the tutorial on socket.io's website. I've got it working on my local machine, but now I'm trying to upload it to an OpenShift Server.
In my app, I have the line:
<script src="/socket.io/socket.io.js"></script>
On my local machine, it loads fine, but on my server, it returns a 404 error. I thought that my node_modules
might not be loading at first, but after shh-ing into the server and checking, I see they are present.
My dependencies in my package.json
are as follows:
"dependencies": {
"express": "^3.4.8",
"socket.io": "^1.1.0"
}
There are many different questions on here about getting a 404 error from socket.io and I've gone threw many of them them attempting to solve this issue, with no progress. Including changing the script
src to:
http://app-domain.rhccloud.com
http://app-domain.rhccloud.com:8000
http://app-domain.rhccloud.com:8080
ws://app-domain.rhchloud.com:
Most of the suggestions aren't specific to an OpenShift server so I figured I'd ask specifically about it.
If needed, here's my server.js
:
#!/bin/env node
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var ip = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
app.get('/', function(req, res){
res.sendfile('index.html');
});
app.listen(port,ip,function() {
console.log('listening');
});
io.on('connection',function(socket) {
console.log('a user connected');
socket.on('disconnect',function() {
console.log('user disconnected');
});
socket.on('chat message',function(msg) {
io.emit('chat message',msg);
});
});
Thanks for any assistance.