File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' nextjs-koa-api ' : patch
3+ ---
4+
5+ add code comments
Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ export class KoaApi<
5858 }
5959 }
6060
61+ /**
62+ * Run koa api with request and response objects
63+ * @param req - nextjs request
64+ * @param res - nextjs response
65+ */
6166 async run ( req : NextApiRequest , res : NextApiResponse ) {
6267 const p = new Promise ( ( resolve ) => onFinished ( res , resolve ) )
6368
@@ -74,6 +79,11 @@ export class KoaApi<
7479 }
7580}
7681
82+ /**
83+ * Helper function for Next.js api routes that automatically runs the KoaApi.
84+ * It should be used as default export from the Next.js api route file
85+ * @param koa - KoaApi to run
86+ */
7787export function withKoaApi ( koa : KoaApi < any , any > ) {
7888 return ( req : NextApiRequest , res : NextApiResponse ) => koa . run ( req , res )
7989}
You can’t perform that action at this time.
0 commit comments