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

How do dev-servers of other frameworks/libraries work on single port? #51

Closed
saurabhdaware opened this issue Jul 14, 2020 · 2 comments
Closed
Labels
dev-server Issue/PR related to dev server help wanted Extra attention is needed question Further information is requested

Comments

@saurabhdaware
Copy link
Member

In abell-dev-server, we have to run a http server on localhost:5000 and a socket server on localhost:3000.

Then we connect the http server to the socket server and every time a change occurs in a file, we send a reload command to http server through websocket.

How is this supposed to work without websocket server?

@saurabhdaware saurabhdaware added help wanted Extra attention is needed question Further information is requested dev-server Issue/PR related to dev server labels Jul 14, 2020
@saurabhdaware saurabhdaware changed the title How do dev-servers of other frameworks/libraries work on same port? How do dev-servers of other frameworks/libraries work on single port? Jul 14, 2020
@saurabhdaware
Copy link
Member Author

Oh ok I just found an example in ws library

const http = require('http');
const WebSocket = require('ws');
const url = require('url');

const server = http.createServer();
const wss1 = new WebSocket.Server({ noServer: true });
const wss2 = new WebSocket.Server({ noServer: true });

wss1.on('connection', function connection(ws) {
  // ...
});

wss2.on('connection', function connection(ws) {
  // ...
});

server.on('upgrade', function upgrade(request, socket, head) {
  const pathname = url.parse(request.url).pathname;

  if (pathname === '/foo') {
    wss1.handleUpgrade(request, socket, head, function done(ws) {
      wss1.emit('connection', ws, request);
    });
  } else if (pathname === '/bar') {
    wss2.handleUpgrade(request, socket, head, function done(ws) {
      wss2.emit('connection', ws, request);
    });
  } else {
    socket.destroy();
  }
});

server.listen(8080);

@saurabhdaware
Copy link
Member Author

Let's track this in #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-server Issue/PR related to dev server help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant