ws-multipath
ws-multipath
is a wrapper around websockets/ws
that provides the ability to attach multiple WebSocket servers to one shared HTTP server to handle multiple paths.
Why?
Have you ever wanted to serve multiple WebSocket endpoints using a single port/server. You might have tried something that looked a little bit like this:
const Server = ; const PORT = 1234; const server1 = port: PORT path:'/notifications' ;const server2 = port: PORT path:'/messages' ;
Soon after, you realize that it's not possible. Not easily, at least.
Having multiple WebSocket servers on the same port can be a messy process. So I decided to write ws-multipath
in hopes of simplifying this task.
How?
In order to have multiple WebSockets server running on the same port, a developer would have to create multiple "serverless" WebSocket.Server
s (using the noServer
option) and utilize one shared HTTP server that delegates requests to the proper WebSocket server.
Sounds complicated, right? That's all what ws-multipath
does!
Example
const MultipathServer = ; const server = port: 1234 ; const foo = server;const bar = server; // handle sockets connecting to ws://localhost:1234/foofoo; // handle sockets connecting to ws://localhost:1234/barbar;
Documentation
Please note that this is experimental and under active development. Therefore, it may have numerous bugs, and the API is subject to change.
See /docs/api.md
for full API documentation.
Installation
To install ws-multipath
, you must have ws
installed as well.
# ws is a peer-dependency of ws-multipath # using npm npm install --save ws ws-multipath # using yarn yarn add ws ws-multipath
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT