Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
This is 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 browservers
var http = require("http")
var engine = require("engine.io")
var brow = require("browserver")
function handler(req, res) {
// your usual HTTP server logic
}
// instantiate http and websocket servers
var httpServer = http.createServer(handler)
var wsServer = engine.attach(httpServer)
// pass each to a new browserver...
var browServer = new brow.Server
browServer.listen(wsServer)
browServer.listen(httpServer, {hostname: "*.mydomain.org"})
// ... and start listening!
httpServer.listen(80, function() {
// wait for incoming/outgoing browser connections...
})
browserver is available through npm.
npm install browserver
This creates a new browserver proxy, which works by listening to both a WebSocket-alike server and an HTTP server.
webSocketServer
is required, and must be an instance of a WebSocket server (such as ws) or compatible shim (such as socket.io, engine.io) that emits socket instances through connection
events.
options
is an optional object that can have any of the following properties:
authorize
: An optional request method used for authorization of client requests FROM the browser. This method is invoked with the request as the this
context and a callback as the first argument (authorize.call(request, callback)
). If this method calls back without an error, the request will be passed on. If this method calls back with an error, a 403 is returned with the error message as the body of the response. By default, browserver will forward-proxy any request from a browser to the greater Internet, so use this method to limit the resources to which browserver clients have access.httpServer
is required, and can either be an instance of http.Server
, or a primitive (such as 3572
or undefined
) to be used as the port on which a new server instance will listen.
options
is an optional object that can have any of the following properties:
hostname
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 127.0.0.1
.
authorize
: An optional request method used for authorization of server requests TO the browser. This method is invoked with the request as the this
context and a callback as the first argument (authorize.call(request, callback)
). If this method calls back without an error, the request will be passed on to the browserver client. If this method calls back with an error, a 403 is returned with the error message as the body of the response. By default, browserver will reverse-proxy any request from the greater Internet to a browserver clients, so use this method to authenticate or limit the requests actually sent to which browserver clients.
The browserver server proxy emits a connection
event whenever a browserver client connects. The listener is called with one argument, the browserver server. The server's unique hostname is available at the hostname
propery.
The browserver server proxy emits a disconnection
event whenever a browserver client disconnects. The listener is called with one argument, the disconnected browserver server.
FAQs
෴ A browserver proxy for node.js ෴
We found that browserver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.