෴ A browserver proxy for node.js ෴
Use browserver-node to create servers that act as a two-way proxies between an HTTP server and a WebSocket server, by
This library, along with browserver-client, is all the code you need to set up your own browserver.
// http, websocket, and browserversvar http = require"http"var engine = require"engine.io"var brow = require"brow"// your usual HTTP server logic// instantiate http and websocket serversvar httpServer = httpcreateServerhandlervar wsServer = engineattachhttpServer// pass each to a new browserver...var browServer =http: httpServerws: wsServerhost: "*.mydomain.org"// ... and start listening!httpServerlisten80// wait for incoming/outgoing browser connections...
browserver is available through npm.
npm install brow
This joins a WebSocket server and HTTP server, returning a new browserver instance. The
options argument accepts the following properties:
http: Optional. If specified, must be an instance of
http.Server. If omitted, an instance will be instantiated and bound to port
3572 (the Unicode codepoint for the brow
host Optional. If specified, must be a string containing one and only one asterisk (
*), which is replaced with a socket id when a WebSocket connection is established. Note that this means you will need a wildcard CNAME or A record in your DNS settings that resolves to the appropriate domain or IP address. If omitted, CloudFoundry's *.vcap.me domain is used, which resolves all domains/subdomains to
The browserver server emits a
connection event with a WebSocket-connected browserver client, whenever one connects. Each client is an instance of
brow.Client, with an
id property that defaults to a random lowercase alphanumeric string generated upon instantiation. How these ids are generated can be customized by overriding the static
browserver clients emit a
close event when their underlying WebSocket is closed.