mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
27 lines
741 B
TypeScript
27 lines
741 B
TypeScript
import { serve } from "@hono/node-server";
|
|
import { config } from "./config.js";
|
|
import logger from "./utils/logger.js";
|
|
import app from "./app.js";
|
|
|
|
// 启动服务器
|
|
const serveHotApi: (port?: number) => void = (port: number = config.PORT) => {
|
|
try {
|
|
const apiServer = serve({
|
|
fetch: app.fetch,
|
|
port,
|
|
});
|
|
logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`);
|
|
logger.info(`💻 Puppeteer: ${config.USE_PUPPETEER}`);
|
|
logger.info(`🔗 Local: 👉 http://localhost:${port}`);
|
|
return apiServer;
|
|
} catch (error) {
|
|
logger.error(error);
|
|
}
|
|
};
|
|
|
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "docker") {
|
|
serveHotApi(config.PORT);
|
|
}
|
|
|
|
export default serveHotApi;
|