1import { AddressInfo } from "net"; 2import * as express from "express"; 3import * as bodyParser from "body-parser"; 4import { Connection } from "typeorm"; 5import { makeExpressEntityRouters } from "@entity-routes/express"; 7export async function setupExpressApp(connection: Connection) { 8 const entities = connection.entityMetadatas.map((meta) => meta.target) as Function[]; 10 const bridgeRouters = await makeExpressEntityRouters({ connection, entities, options }); 11 const app = express(); 12 app.use(bodyParser.json()); 13 app.use(bodyParser.urlencoded({ extended: true })); 16 bridgeRouters.forEach((router) => app.use(router.instance)); 18 const server = app.listen(); 19 const baseURL = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; 20 const client = axios.create({ baseURL }); 21 return { baseURL, server, client };