entity-routes logo
Docs

Express/Next/Nuxt#

#
typescript
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 }));
15 // Register all routes on Express server
16 bridgeRouters.forEach((router) => app.use(router.instance));
18 const server = app.listen(); // random port
19 const baseURL = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
20 const client = axios.create({ baseURL });
21 return { baseURL, server, client };
Prev
@OrderBy
Next
Koa