1- import Router , { RouterOptions } from '@koa/router'
1+ import Router from '@koa/router'
22import Koa from 'koa'
33import type { NextApiRequest , NextApiResponse } from 'next'
44import onFinished from 'on-finished'
@@ -11,7 +11,8 @@ declare module 'koa' {
1111 }
1212}
1313
14- export type { Router , RouterOptions }
14+ export { Router }
15+ export { Koa }
1516
1617export type KoaOptions = {
1718 env ?: string
@@ -29,8 +30,11 @@ export type KoaApiOptions = {
2930 routerAllowedMethods ?: Router . RouterAllowedMethodsOptions
3031}
3132
32- export class KoaApi extends Koa {
33- router : Router
33+ export class KoaApi <
34+ TState extends Koa . DefaultState = Koa . DefaultState ,
35+ TContext extends Koa . DefaultContext = Koa . DefaultContext
36+ > extends Koa < TState , TContext > {
37+ router : Router < TState , TContext >
3438
3539 protected firstRun = true
3640
@@ -47,9 +51,9 @@ export class KoaApi extends Koa {
4751 this . router = new Router ( this . options . router )
4852
4953 if ( this . options . attachBody ) {
50- this . use ( ( ctx , next ) => {
54+ this . use ( async ( ctx , next ) => {
5155 ctx . request . body = ctx . req . body
52- next ( )
56+ await next ( )
5357 } )
5458 }
5559 }
@@ -68,12 +72,8 @@ export class KoaApi extends Koa {
6872
6973 return p
7074 }
71-
72- createNewRouter ( opts ?: RouterOptions ) {
73- return new Router ( opts )
74- }
7575}
7676
77- export function withKoaApi ( koa : KoaApi ) {
77+ export function withKoaApi ( koa : KoaApi < any , any > ) {
7878 return ( req : NextApiRequest , res : NextApiResponse ) => koa . run ( req , res )
7979}
0 commit comments