在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koajs/mount开源软件地址:https://github.com/koajs/mount开源编程语言:JavaScript 100.0%开源软件介绍:koa-mountMount other Koa applications as middleware. The Installation$ npm install koa-mount ExamplesView the ./examples directory for working examples. Mounting ApplicationsEntire 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 = require('koa-mount');
const Koa = require('koa');
// hello
const a = new Koa();
a.use(async function (ctx, next){
await next();
ctx.body = 'Hello';
});
// world
const b = new Koa();
b.use(async function (ctx, next){
await next();
ctx.body = 'World';
});
// app
const app = new Koa();
app.use(mount('/hello', a));
app.use(mount('/world', b));
app.listen(3000);
console.log('listening on port 3000'); Try the following requests:
Mounting MiddlewareMount middleware at specific paths, allowing them to operate independently of the prefix, as they're not aware of it. const mount = require('koa-mount');
const Koa = require('koa');
async function hello(ctx, next){
await next();
ctx.body = 'Hello';
}
async function world(ctx, next){
await next();
ctx.body = 'World';
}
const app = new Koa();
app.use(mount('/hello', hello));
app.use(mount('/world', world));
app.listen(3000);
console.log('listening on port 3000'); Optional PathsThe path argument is optional, defaulting to "/": app.use(mount(a));
app.use(mount(b)); DebuggingUse the DEBUG environement variable to whitelist koa-mount debug output:
LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论