// 日志、全局插件、定时任务等基础设施 import { consoleLogger } from "./logger.js" import "./jobs/index.js" // 第三方依赖 import Koa from "koa" import os from "os" // 应用插件与自动路由 import LoadMiddlewares from "./middlewares/install.js" const app = new Koa() // 注册插件 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() consoleLogger.trace(`===================【服务器地址】====================`) consoleLogger.trace(` http://localhost:${port} (本地地址) `) consoleLogger.trace(` http://${localIP}:${port} (本地地址) `) consoleLogger.trace(`===================【服务器地址】====================`) }) export default app