Run paired with a Node http/https server? #59

Open
opened 2019-07-31 16:30:46 +00:00 by Pomax · 0 comments
Pomax commented 2019-07-31 16:30:46 +00:00 (Migrated from github.com)

Is there a way to hand ws an http.createServer() / https.createServer() instance, so that a server can handle (limited) HTTP traffic in addition to upgrading a connection to a websocket connection on a specific route?

For instance:

const https = require('https');
const ws = require('node-websocket');
const routes = require('./routes.js');
const server = https.createServer(routes);
ws.setUpgradePath(server, 'join', connection => {
  connection.on( ... )
  ...
});
server.listen(80);

So we have a simple secure http server, with a route that clients can use when creating websockets in order to set up the two way persistent connection, while also being able to load up (for example) a lobby page on the / route that gives them information on who else is already connected, a button that starts their own websocket client code, etc.

Especially for debugging and administration, being able to generate a webpage that shows the current server state on the same address and port (but not path), rather than using a separate server entirely, is fairly crucial.

Is there a way to hand ws an `http.createServer()` / `https.createServer()` instance, so that a server can handle (limited) HTTP traffic in addition to upgrading a connection to a websocket connection on a specific route? For instance: ```javascript const https = require('https'); const ws = require('node-websocket'); const routes = require('./routes.js'); const server = https.createServer(routes); ws.setUpgradePath(server, 'join', connection => { connection.on( ... ) ... }); server.listen(80); ``` So we have a simple secure http server, with a route that clients can use when creating websockets in order to set up the two way persistent connection, while also being able to load up (for example) a lobby page on the `/` route that gives them information on who else is already connected, a button that starts their own websocket client code, etc. Especially for debugging and administration, being able to generate a webpage that shows the current server state on the same address and port (but not path), rather than using a separate server entirely, is fairly crucial.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sitegui/nodejs-websocket#59
No description provided.