logoran-mount
Mount other Logoran applications as middleware. The path
passed to mount()
is stripped
from the URL temporarily until the stack unwinds. This is useful for creating entire
apps or middleware that will function correctly regardless of which path segment(s)
they should operate on.
Installation
$ npm install logoran-mount
Examples
View the ./examples directory for working examples.
Mounting Applications
Entire applications mounted at specific paths. For example you could mount a blog application at "/blog", with a router that matches paths such as "GET /", "GET /posts", and will behave properly for "GET /blog/posts" etc when mounted.
const mount = ;const Logoran = ; // hello const a = ; a; // world const b = ; b; // app const app = ; app;app; app;console;
Try the following requests:
$ GET /
Not Found
$ GET /hello
Hello
$ GET /world
World
Mounting Middleware
Mount middleware at specific paths, allowing them to operate independently of the prefix, as they're not aware of it.
const mount = ;const Logoran = ; { await ; ctxbody = 'Hello';} { await ; ctxbody = 'World';} const app = ; app;app; app;console;
Optional Paths
The path argument is optional, defaulting to "/":
app;app;
Debugging
Use the DEBUG environement variable to whitelist logoran-mount debug output:
$ DEBUG=logoran-mount node myapp.js &
$ GET /foo/bar/baz
logoran-mount enter /foo/bar/baz -> /bar/baz +2s
logoran-mount enter /bar/baz -> /baz +0ms
logoran-mount enter /baz -> / +0ms
logoran-mount leave /baz -> / +1ms
logoran-mount leave /bar/baz -> /baz +0ms
logoran-mount leave /foo/bar/baz -> /bar/baz +0ms
License
MIT