- 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
- 42
- 43
- 44
app.use((ctx, next) => {
console.log('Middleware 1 start')
ctx.body = {}
return next().then(() => {
ctx.body.middleware1Says = 'Middleware 1 here'
ctx.body.last = 1
console.log('Middleware 1 done')
})
})
app.use((ctx, next) => {
console.log('Middleware 2 start')
return next().then(() => {
ctx.body.middleware2Says = 'Middleware 2 here'
ctx.body.last = 2
console.log('Middleware 2 done')
})
})
app.use((ctx, next) => {
console.log('Middleware 3 start')
return next().then(() => {
ctx.body.middleware3Says = 'Middleware 3 here'
ctx.body.last = 3
console.log('Middleware 3 done')
})
})
// Expected log:
// Middleware 1 start
// Middleware 2 start
// Middleware 3 start
// Middleware 3 done
// Middleware 2 done
// Middleware 1 done
// Expected result:
{
"middleware3Says": "Middleware 3 here",
"middleware2Says": "Middleware 2 here",
"middleware1Says": "Middleware 1 here",
"last": 1
}