File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
example/src/pages/api/level_one Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1- import { KoaApi , withKoaApi } from 'nextjs-koa-api'
1+ import { Koa , KoaApi , Router , withKoaApi } from 'nextjs-koa-api'
22
3- const api = new KoaApi ( {
3+ interface ApiState extends Koa . DefaultState {
4+ seesion : boolean
5+ }
6+ interface ApiContext extends Koa . Context {
7+ user : { name : string }
8+ }
9+ const api = new KoaApi < ApiState , ApiContext > ( {
410 router : {
511 prefix : '/api/level_one'
612 }
713} )
14+ api . context . user = { name : 'Lionel' }
815
916api . use ( async ( ctx , next ) => {
17+ // ctx.user.name
18+ // ctx.state.seesion
1019 try {
1120 await next ( )
1221 } catch ( err : any ) {
@@ -35,7 +44,7 @@ api.router
3544 } )
3645
3746// create nested router
38- const subRouter = api . createNewRouter ( ) . get ( '/' , ( ctx ) => {
47+ const subRouter = new Router < ApiState , ApiContext > ( ) . get ( '/' , ( ctx ) => {
3948 ctx . body = `nested params: ${ JSON . stringify ( ctx . params ) } `
4049} )
4150
You can’t perform that action at this time.
0 commit comments