entity-routes logo
Docs

Koa#

#
typescript
1import { AddressInfo } from "net";
2import * as Koa from "koa";
3import * as bodyParser from "koa-bodyparser";
4import { Connection } from "typeorm";
5import { makeKoaEntityRouters } from "@entity-routes/koa";
7export async function setupKoaApp(connection: Connection) {
8 const entities = connection.entityMetadatas.map((meta) => meta.target) as Function[];
10 const bridgeRouters = await makeKoaEntityRouters({ connection, entities, options });
11 const app = new Koa();
12 app.use(bodyParser());
14 // Register all routes on koa server
15 bridgeRouters.forEach((router) => app.use(router.instance.routes()));
17 const server = app.listen(); // random port
18 const baseURL = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
19 return { baseURL, server };
Prev
Express/Next/Nuxt
Next
Making a custom ContextAdapter