nextjs-koa-api
Ƭ KoaApiOptions: Object
Koa API options
Name | Type | Description |
---|---|---|
attachBody? |
boolean |
if parsed body from Nextjs request should be attached to ctx.request |
koa? |
KoaOptions |
original koa options |
router? |
RouterOptions |
Router.RouterOptions |
routerAllowedMethods? |
RouterAllowedMethodsOptions |
Router.RouterAllowedMethodsOptions |
Ƭ KoaOptions: Object
Name | Type | Description |
---|---|---|
env? |
string |
defaulting to the NODE_ENV or "development" |
keys? |
string [] |
array of signed cookie keys |
maxIpsCount? |
number |
max ips read from proxy ip header, default to 0 (means infinity) |
proxy? |
boolean |
when true proxy header fields will be trusted |
proxyIpHeader? |
string |
proxy ip header, default to X-Forwarded-For |
subdomainOffset? |
number |
offset of .subdomains to ignore, default to 2 |
▸ attachRouter(path
, app
, router
): void
Attaches router to a particular path. Internally it setups a prefix on the router, and calls router.routes()
and router.allowedMethods()
Name | Type | Description |
---|---|---|
path |
string |
path to attach the router to |
app |
KoaApi <any , any > |
- |
router |
Router <any , any > |
router to attach |
void
lib/koa-api/src/koa-api.ts:108
▸ withKoaApi(koa
): (req
: NextApiRequest
, res
: NextApiResponse
<any
>) => Promise
<unknown
>
Helper function for Next.js api routes that automatically runs the KoaApi. It should be used as default export from the Next.js api route file
Name | Type | Description |
---|---|---|
koa |
KoaApi <any , any > |
KoaApi to run |
fn
▸ (req
, res
): Promise
<unknown
>
Name | Type |
---|---|
req |
NextApiRequest |
res |
NextApiResponse <any > |
Promise
<unknown
>