Skip to content

Latest commit

 

History

History
128 lines (78 loc) · 4.58 KB

README.md

File metadata and controls

128 lines (78 loc) · 4.58 KB

nextjs-koa-api

nextjs-koa-api

Table of contents

Namespaces

Classes

Type aliases

Functions

Type aliases

KoaApiOptions

Ƭ KoaApiOptions: Object

Koa API options

Type declaration

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

Defined in

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


KoaOptions

Ƭ KoaOptions: Object

Type declaration

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

Defined in

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

Functions

attachRouter

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()

Parameters

Name Type Description
path string path to attach the router to
app KoaApi<any, any> -
router Router<any, any> router to attach

Returns

void

Defined in

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


withKoaApi

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

Parameters

Name Type Description
koa KoaApi<any, any> KoaApi to run

Returns

fn

▸ (req, res): Promise<unknown>

Parameters
Name Type
req NextApiRequest
res NextApiResponse<any>
Returns

Promise<unknown>

Defined in

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