Code:
var express = require('express');
var connect = require('connect');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var path = require('path');
server.listen(3000, "0.0.0.0");
app.all('*', function(req, res) {
if(req.originalUrl.slice(-3) == "css" || req.originalUrl.slice(-4) == "html" ||
req.originalUrl.slice(-2) == "js" || req.originalUrl.slice(-3) == "png" ||
req.originalUrl.slice(-3) == "jpg" || req.originalUrl.slice(-4) == "jpeg" || req.originalUrl.slice(-3) == "gif") {
res.sendFile(__dirname + req.originalUrl);
} else {
res.sendFile(__dirname + req.originalUrl + "/index.html");
}
});
io.sockets.on('connection', function(socket) {
socket.on('sendMsg', function(data) {
io.sockets.emit('newMsg', data);
});
socket.on('login', function(data) {
if(data == "root") {
socket.emit('authStatus', "Good nick");
} else {
socket.emit('authStatus', "Wrong nick");
}
});
});
Works 100% on localhost. But doesn't work on any other device on LAN. Can you help me, please?
EDIT: It don't even load site on another device on LAN.
Best Answer
It's hard to say what's wrong for sure but here are the things to check:
You have to go through the list of possible issues one by one to narrow down the problem.