npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browserver

v0.1.2

Published

෴ A browserver proxy for node.js ෴

Downloads

7

Readme

෴ browserver-node ෴

Build Status

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

  • forwarding incoming HTTP requests on to WebSocket connected clients, and back.
  • forwarding incoming WebSocket messages to other HTTP servers, and back.

This library, along with browserver-client, is all the code you need to set up your own browserver.

Example

// http, websocket, and browservers
var http   = require("http")
var engine = require("engine.io")
var brow   = require("brow")

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...
})

Installation

browserver is available through npm.

npm install brow

API

browserver = new brow.Server

This creates a new browserver proxy, which works by listening to both a WebSocket-alike server and an HTTP server.

browserver.listen(webSocketServer, [options])

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.

browserver.listen(httpServer, [options])

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.

browserver.on("connection", function(hostname){ ... })

The browserver server proxy emits a connection event whenever a browserver client connects. The listener is called with one argument, the hostname of the browserver client.

browserver.on("disconnection", function(hostname){ ... })

The browserver server proxy emits a disconnection event whenever a browserver client disconnects. The listener is called with one argument, the hostname of the browserver client.