Skip to content
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

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

Open
Pomax opened this issue Jul 31, 2019 · 0 comments
Open

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

Pomax opened this issue Jul 31, 2019 · 0 comments

Comments

@Pomax
Copy link

Pomax commented Jul 31, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant