forked from koajs/mount
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcascade.js
More file actions
41 lines (33 loc) · 708 Bytes
/
cascade.js
File metadata and controls
41 lines (33 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* This example illustrates how you may
* implement a cascading effect using
* several mounted applications that
* are not aware of where they are mounted:
*
* GET /foo
* GET /foo/bar
* GET /foo/bar/baz
*/
var mount = require('..');
var koa = require('koa');
var app = koa();
var a = koa();
var b = koa();
var c = koa();
a.use(function *(next){
yield next;
if (!this.body) this.body = 'foo';
});
b.use(function *(next){
yield next;
if (!this.body) this.body = 'bar';
});
c.use(function *(next){
yield next;
this.body = 'baz';
});
app.use(mount('/foo', a));
a.use(mount('/bar', b));
b.use(mount('/baz', c));
app.listen(3000);
console.log('listening on port 3000');