koa-mount-final
koa-mount-final
is a wrapper around koa-mount which prevents matched (but unhandled) requests from falling down the middleware stack.
All requests under /prefix
will either be handled by the mounted middleware, or the stack will be immediately unwinded (probably returning HTTP 404
).
This is useful when you have API server and catch-all frontend server (e.g. Nuxt.js) running under the same Koa instance, and want to make sure that the frontend will never see any API requests (even those that were not handled by the API server).
Example
const Koa = ;const mount = ;const mountFinal = const Router = const api = api { ctxbody = '<h1>Hello, world!</h1>'} const app = ;appappapp appconsole
The difference between koa-mount
and koa-mount-final
will be in handling missing routes under /api
:
$ GET /<h1>Hello, world!</h1> $ GET /api/v1/pingpong $ GET /api/v2/pingpong $ GET /api/v1/wazzup<h1>Hello, world!</h1> $ GET /api/v2/wazzupNot Found
Typescript
The module provides Typescript bindings. They are auto generated and don't use the empty namespace hack. You will probably need to enable esModuleInterop
in your project.