generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.ts
24 lines (20 loc) · 1.1 KB
/
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
24
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()
const commitHash = (await components.config.getString('COMMIT_HASH')) ?? ''
components.metrics.observe('dcl_lamb2_server_build_info', { commitHash }, 1)
}