mirror of
https://github.com/hcengineering/platform.git
synced 2025-03-29 19:45:59 +00:00
37 lines
930 B
TypeScript
37 lines
930 B
TypeScript
//
|
|
// Copyright © 2024 Hardcore Engineering Inc.
|
|
//
|
|
|
|
import { setMetadata } from '@hcengineering/platform'
|
|
import serverToken from '@hcengineering/server-token'
|
|
|
|
import { storageConfigFromEnv } from '@hcengineering/server-storage'
|
|
import config from './config'
|
|
import { createServer, listen } from './server'
|
|
|
|
const setupMetadata = (): void => {
|
|
setMetadata(serverToken.metadata.Secret, config.Secret)
|
|
}
|
|
|
|
export const main = async (): Promise<void> => {
|
|
setupMetadata()
|
|
|
|
const storageConfig = storageConfigFromEnv()
|
|
const { app, close } = createServer(config.DbURL, storageConfig)
|
|
const server = listen(app, config.Port)
|
|
|
|
const shutdown = (): void => {
|
|
close()
|
|
server.close(() => process.exit())
|
|
}
|
|
|
|
process.on('SIGINT', shutdown)
|
|
process.on('SIGTERM', shutdown)
|
|
process.on('uncaughtException', (e) => {
|
|
console.error(e)
|
|
})
|
|
process.on('unhandledRejection', (e) => {
|
|
console.error(e)
|
|
})
|
|
}
|