-
Notifications
You must be signed in to change notification settings - Fork 2
/
components.ts
29 lines (26 loc) · 1.13 KB
/
components.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
25
26
27
28
29
import { createDotEnvConfigComponent } from '@well-known-components/env-config-provider'
import {
createServerComponent,
createStatusCheckComponent,
instrumentHttpServerWithPromClientRegistry
} from '@well-known-components/http-server'
import { createLogComponent } from '@well-known-components/logger'
import { createMetricsComponent } from '@well-known-components/metrics'
import { AppComponents, GlobalContext } from './types'
import { metricDeclarations } from './metrics'
// Initialize all the components of the app
export async function initComponents(): Promise<AppComponents> {
const config = await createDotEnvConfigComponent({ path: ['.env.default', '.env'] })
const metrics = await createMetricsComponent(metricDeclarations, { config })
const logs = await createLogComponent({ metrics })
const server = await createServerComponent<GlobalContext>({ config, logs }, {})
const statusChecks = await createStatusCheckComponent({ server, config })
await instrumentHttpServerWithPromClientRegistry({ metrics, server, config, registry: metrics.registry! })
return {
config,
logs,
server,
statusChecks,
metrics
}
}