main.js
1.05 KB
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
30
31
32
33
34
35
36
37
38
/**
* `@voko/server` 进程入口:runtime → app → listen → close。
*/
import { buildApp } from './app.js'
import { createRuntime } from './assembly/runtime.js'
async function start() {
const runtime = await createRuntime({ service: '@voko/server' })
const app = buildApp({ services: runtime.services, logger: runtime.logger })
await app.listen({ port: runtime.env.port, host: '0.0.0.0' })
runtime.logger.info('服务已启动', { port: runtime.env.port, environment: runtime.env.nodeEnv })
return {
async close() {
await app.close()
await runtime.close()
},
}
}
start()
.then(({ close }) => {
const stop = async (signal) => {
try {
await close()
process.exit(0)
} catch (err) {
console.error(`voko-server failed to stop after ${signal}:`, err)
process.exit(1)
}
}
process.once('SIGINT', () => stop('SIGINT'))
process.once('SIGTERM', () => stop('SIGTERM'))
})
.catch((err) => {
console.error('voko-server failed to start:', err)
process.exit(1)
})