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()); 15 bridgeRouters.forEach((router) => app.use(router.instance.routes())); 17 const server = app.listen(); 18 const baseURL = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; 19 return { baseURL, server };