File size: 1,284 Bytes
1034ef4 c1fb6e6 042a329 1034ef4 4e1f6f0 042a329 c1fb6e6 1034ef4 4e1f6f0 c1fb6e6 042a329 c1fb6e6 4e1f6f0 1034ef4 | 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 39 40 41 42 43 | /**
* 本地开发启动入口。
*/
import app from './app.js'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const PORT = Number(process.env.PORT || 3210)
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const projectRootDir = path.resolve(__dirname, '..', '..')
const distDir = path.resolve(projectRootDir, 'dist')
process.on('unhandledRejection', (reason) => {
console.error('未处理的 Promise 拒绝:', reason)
})
process.on('uncaughtException', (error) => {
console.error('未捕获的异常:', error)
process.exit(1)
})
const server = app.listen(PORT, '0.0.0.0', () => {
console.log(
`[boot] NODE_ENV=${process.env.NODE_ENV || ''} PORT=${PORT} cwd=${process.cwd()} root=${projectRootDir} distDir=${distDir} distExists=${fs.existsSync(distDir)} DATA_DIR=${process.env.DATA_DIR || ''}`,
)
console.log(`API 服务已启动:http://0.0.0.0:${PORT}`)
})
function shutdown(signal: string) {
console.log(`${signal} 信号已接收,正在关闭服务...`)
server.close(() => {
console.log('服务已关闭')
process.exit(0)
})
}
process.on('SIGTERM', () => shutdown('SIGTERM'))
process.on('SIGINT', () => shutdown('SIGINT'))
export default app
|