You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.6 KiB
41 lines
1.6 KiB
import { app } from "./global"
|
|
// 日志、全局插件、定时任务等基础设施
|
|
import { logger } from "./logger.js"
|
|
import "./jobs/index.js"
|
|
|
|
// 第三方依赖
|
|
import os from "os"
|
|
|
|
// 应用插件与自动路由
|
|
import LoadMiddlewares from "./middlewares/install.js"
|
|
|
|
// 注册插件
|
|
LoadMiddlewares(app)
|
|
|
|
const PORT = process.env.PORT || 3000
|
|
|
|
const server = app.listen(PORT, () => {
|
|
const port = server.address().port
|
|
// 获取本地 IP
|
|
const getLocalIP = () => {
|
|
const interfaces = os.networkInterfaces()
|
|
for (const name of Object.keys(interfaces)) {
|
|
for (const iface of interfaces[name]) {
|
|
if (iface.family === "IPv4" && !iface.internal) {
|
|
return iface.address
|
|
}
|
|
}
|
|
}
|
|
return "localhost"
|
|
}
|
|
const localIP = getLocalIP()
|
|
logger.trace(`──────────────────── 服务器已启动 ────────────────────`)
|
|
logger.trace(` `)
|
|
logger.trace(` 本地访问: http://localhost:${port} `)
|
|
logger.trace(` 局域网: http://${localIP}:${port} `)
|
|
logger.trace(` `)
|
|
logger.trace(` 服务启动时间: ${new Date().toLocaleString()} `)
|
|
logger.trace(`──────────────────────────────────────────────────────\n`)
|
|
})
|
|
|
|
export default app
|
|
|