Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Mount other Koa 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.
$ npm install koa-mount
View the ./examples directory for working examples.
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.
var mount = require('koa-mount');
var koa = require('koa');
// hello
var a = koa();
a.use(function *(next){
yield next;
this.body = 'Hello';
});
// world
var b = koa();
b.use(function *(next){
yield next;
this.body = 'World';
});
// app
var app = koa();
app.use(mount('/hello', a));
app.use(mount('/world', b));
app.listen(3000);
console.log('listening on port 3000');
Try the following requests:
$ GET /
Not Found
$ GET /hello
Hello
$ GET /world
World
Mount middleware at specific paths, allowing them to operate independently of the prefix, as they're not aware of it.
var mount = require('koa-mount');
var koa = require('koa');
function *hello(next){
yield next;
this.body = 'Hello';
}
function *world(next){
yield next;
this.body = 'World';
}
var app = koa();
app.use(mount('/hello', hello));
app.use(mount('/world', world));
app.listen(3000);
console.log('listening on port 3000');
The path argument is optional, defaulting to "/":
app.use(mount(a));
app.use(mount(b));
Use the DEBUG environement variable to whitelist koa-mount debug output:
$ DEBUG=koa-mount node myapp.js &
$ GET /foo/bar/baz
koa-mount enter /foo/bar/baz -> /bar/baz +2s
koa-mount enter /bar/baz -> /baz +0ms
koa-mount enter /baz -> / +0ms
koa-mount leave /baz -> / +1ms
koa-mount leave /bar/baz -> /baz +0ms
koa-mount leave /foo/bar/baz -> /bar/baz +0ms
MIT
FAQs
Mounting middleware for koa
The npm package koa-mount receives a total of 65,052 weekly downloads. As such, koa-mount popularity was classified as popular.
We found that koa-mount demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.