Skip to content

Commit 5d9095b

Browse files
committed
add code comments
1 parent 23f1e9c commit 5d9095b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/gold-jars-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextjs-koa-api': patch
3+
---
4+
5+
add code comments

lib/koa-api/src/koa-api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
*/
7787
export function withKoaApi(koa: KoaApi<any, any>) {
7888
return (req: NextApiRequest, res: NextApiResponse) => koa.run(req, res)
7989
}

0 commit comments

Comments
 (0)