mountie
Compose web servers behind host headers and mount paths using seaport and bouncy.
example
First write a mountie hub:
var mountie = ;var seaport = ;var ports = seaport;ports;var server = ;server;
Next write web servers that register themselves to listen on hostnames:
var http = ;var ports = ;var server = http;ports;
and additional web servers can sit at specific mount points (or on entirely different host names):
var http = ;var ports = ;var server = http;ports;
Then spin up all the processes (in any order) and everything should just work!
$ curl http://localhost/
hello cruel world
$ curl http://localhost/beep
boop
$ curl http://localhost/xyz
hello cruel world
Attach as many web servers as you want! Just register them with seaport and mountie will figure everything out dynamically at runtime.
methods
var mountie =
var server = mountie(ports, opts)
Create a new bouncy instance server
that
you can .listen()
on. The server object is extended with the methods
documented below.
ports
must be a seaport server object created with
seaport.createServer()
or with pier,
not a handle created with seaport.connect()
.
You can specify an opts.prefix
to control how the naming for web services in
seaport works. By default, opts.prefix
is 'web'
.
When an incoming request comes in, mountie first searches for mounted routes,
then for services registered as opts.prefix + '.' + req.headers.host
and a mount
field, then for services without a mount field but a matching
host prefix.
When you mount web servers with the mount
field, the leading mount value gets
sliced off the req.url
so that you can more easily juggle mounted servers
around without changing the mount values in as many places.
All other opts
are passed directly to
bouncy.
server.mount(opts, cb)
Attach additional custom logic for handling mounts to be run before handling
entries from seaport. The options in opts
control the matching and when a
request matches, cb(req, bounce)
fires with the request object req
and the
bouncy bounce() function.
When opts
is a function, it will be used as a comparison function that
should return true or false if the req
object passed into it matches.
When opts
is not an object it will be interpreted as the opts.path
value.
When opts.path
is a regexp, matching is determined by .test(req.url)
.
When opts.path
is a string, matching is determined by whether the opts.path
is a path prefix of the req.url
.
You can use opts.method
to add an additional restriction on the http method.
install
With npm do:
npm install mountie
license
MIT