-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the example usage in README #42
Comments
@dolftax sorry for long delay. Do you have any particular suggestions? What isn't clear in current version? |
For me I can not figure out why socket.io stops working... If I remove the if/else it works, but then adding it back it stops working. Am I doing something wrong? Also you should add a list of options/settings with descriptions to the readme. Basically, in the end, could you put a basic socket.io connection example in the usage section. // Import node modules
import http = require('http');
import socketio = require('socket.io');
import redisio = require('socket.io-redis');
const sticky = require('sticky-session');
const server = http.createServer();
const stickyOptions = {
workers: 1
}
if (!sticky.listen(server, 3000, stickyOptions)) {
server.once('listening', () => {
console.log(`Server listening on port 3000`);
});
} else {
const io: SocketIO.Server = socketio(server);
const redis: SocketIORedis.RedisAdapter = redisio({
host: Config.Redis.Host,
port: Config.Redis.Port
});
// Attach redis to socket.io
io.adapter(redis);
io.on('connection', (socket) => {
console.log('User Connected');
});
server.listen(3000);
} |
I believe you don't need |
This example appears to be hanging even without |
I just ran the above code (might need to modify the constants as I was using The result should be Here is the Nginx configuration: upstream io_nodes {
ip_hash;
server 127.0.0.1:3000;
# server 127.0.0.1:3001;
}
server {
listen 80;
server_name api.chat.com;
location / {
proxy_pass http://io_nodes/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-NginX-Proxy true;
#proxy_cache_bypass $http_upgrade;
}
} |
@TheColorRed do you have a reduced test case? May be an |
Here is basic HTML that works <doctype html>
<html>
<head>
<title>Chat</title>
</head>
<body>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
var socket = io('api.chat.com');
</script>
</body>
</html> |
@TheColorRed this appears to be working, could you please verify? const http = require('http');
const socketio = require('socket.io');
const redisio = require('socket.io-redis');
const sticky = require('sticky-session');
const server = http.createServer((req, res) => {
if (req.url === '/') {
res.writeHead(200, {
'content-type': 'text/html'
});
res.end(`<doctype html>
<html>
<head>
<title>Chat</title>
</head>
<body>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
var socket = io('127.0.0.1:3000');
</script>
</body>
</html>`);
return;
}
});
const stickyOptions = {
workers: 1
}
if (!sticky.listen(server, 3000)) {
server.once('listening', () => {
console.log(`Server listening on port 3000`);
});
return;
}
const io = socketio(server);
io.on('connection', (socket) => {
console.log('User Connected');
});
// server.listen(3000); |
How is this supposed to work? Could you please make the Usage section more clear?
The text was updated successfully, but these errors were encountered: