-
Notifications
You must be signed in to change notification settings - Fork 2
/
service.ts
23 lines (20 loc) · 976 Bytes
/
service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Lifecycle } from "@well-known-components/interfaces"
import { setupRouter } from "./controllers/routes"
import { AppComponents, GlobalContext, TestComponents } from "./types"
// this function wires the business logic (adapters & controllers) with the components (ports)
export async function main(program: Lifecycle.EntryPointParameters<AppComponents | TestComponents>) {
const { components, startComponents } = program
const globalContext: GlobalContext = {
components,
}
// wire the HTTP router (make it automatic? TBD)
const router = await setupRouter(globalContext)
// register routes middleware
components.server.use(router.middleware())
// register not implemented/method not allowed/cors responses middleware
components.server.use(router.allowedMethods())
// set the context to be passed to the handlers
components.server.setContext(globalContext)
// start ports: db, listeners, synchronizations, etc
await startComponents()
}