-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: let MiddlewareFunc can extend by custom Context interface
- Loading branch information
Showing
4 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { MiddlewareFunc, Context, type ContextDelegation } from '../../src/index.js'; | ||
|
||
class CustomContext extends Context { | ||
// Add your custom properties and methods here | ||
get hello() { | ||
return 'world'; | ||
} | ||
} | ||
|
||
type ICustomContext = CustomContext & ContextDelegation; | ||
|
||
export const middleware: MiddlewareFunc<ICustomContext> = async (ctx, next) => { | ||
console.log('middleware start, %s', ctx.hello, ctx.writable); | ||
await next(); | ||
console.log('middleware end'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters