Skip to content

Commit

Permalink
docs: fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 30, 2022
1 parent 1defdbc commit 7ef309c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ The final handler is executed when the entire middleware chain ends by calling `
const context = {
stack: [],
}
const middleware = new Middleware()

type MiddlewareFn = (ctx: typeof context, next: NextFn)
const middleware = new Middleware<MiddlewareFn>()

middleware.add((ctx: typeof context, next: NextFn) => {
ctx.stack.push('fn1')
Expand All @@ -117,7 +119,9 @@ To simply the exception handling process, you can define a custom error handler
const context = {
stack: [],
}
const middleware = new Middleware()

type MiddlewareFn = (ctx: typeof context, next: NextFn)
const middleware = new Middleware<MiddlewareFn>()

middleware.add((ctx: typeof context, next: NextFn) => {
ctx.stack.push('middleware 1 upstream')
Expand Down Expand Up @@ -150,6 +154,7 @@ await middleware
assert.deepEqual(context.stack, [
'middleware 1 upstream',
'middleware 2 upstream',
'error handler',
'middleware 1 downstream'
])
```
Expand Down

0 comments on commit 7ef309c

Please sign in to comment.