Module middleware/mount
This module provides middleware for mounting other applications on a specific URI path or virtual host.
Applying this middleware adds a mount
method to the application. The mount
method takes a path or virtual host specification and an application as arguments.
If the spec is a string, it is interpreted as the URI path on which the app will be
mounted. If it is an object, it may contain path
or host
properties
that will be matched against the URI path and Host
header of incoming requests.
Note that virtual host based mounting has not been tested so far.
The mount
method accepts an optional third boolean noRedirect
argument.
If set to true
it will disable redirecting GET requests to the mount base
URL without a trailing slash to the same URL with trailing slash. By default,
mount middleware will send a redirect to the mount URL with trailing slash.
Mounting one application within another causes the scriptName
and pathInfo
properties in the request object to be adjusted so that the mounted application
receives the same pathInfo as if it was the main application. This means
that forward and reverse request routing will usually work as expected.
This middleware maintains an index mapping applications to mount points which can be accessed using the lookup function. The [stick/helpers][helpers] module provides higher level functions for this which include support for the route middleware.
Example
app.configure("mount");
app.mount("/wiki", module.resolve("vendor/ringowiki"));
Functions
- lookup (target)
- middleware (next, app)
lookup (target)
Return the URI path of a mounted application
Parameters
null | target | a mounted JSGI application |
Returns
the URI path of the application, or "" |
middleware (next, app)
Middleware to mount other application on specific URI paths or virtual hosts.
Parameters
Function | next | the wrapped middleware chain |
Object | app | the Stick Application object |
Returns
Function | a JSGI middleware function |