Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including dockmaster with all npm packages installed. Try it out:

var dockmaster = require("dockmaster")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

dockmaster v0.4.0

Vhost middleware router for Distribute that uses Seaport to intelligently route requests

Dockmaster

Dockmaster is a vhost middleware router for Distribute that uses Seaport to intelligently route requests.

npm tag

Usage

Router

var http = require('http')
  , distribute = require('distribute')
  , seaport = require('seaport')
  , dockmaster = require('dockmaster');

// Connect to the Seaport server
var ports = require('seaport').connect(5000);

/*
 * Create the httpServer and register it with Seaport. 
 * The noroute attribute passed to seaport will prevent Docmaster routing to its self.
 */
var httpServer = http.createServer().listen(
  ports.register('router', {noroute: true})
);

// Wrap the httpServer with distribute
var router = distribute(httpServer);

// Use the Dockmaster middleware
router.use(dockmaster(ports));

Applications

For the above router to route to your apps you will need to register your applications with Seaport. As so:

var http = require('http')
  , express = require('express')
  , seaport = require('seaport');

// Connect to the Seaport server
var ports = require('seaport').connect(5000);

// Create your app and register it with Seaport
var app = express();
app.listen(ports.register('myapp', { domains: ['myapp.domain'] }));

You can also mount applications on paths so you can have multiple applications sharing the same domain.

var app = express();
app.listen(ports.register('myapp', { domains: ['myapp.domain'], mount: '/admin' }));

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free