2025-07-25 15:33:48 -07:00
|
|
|
import { initializeServices } from "./src/config/services.js";
|
|
|
|
|
import { initializeControllers } from "./src/config/controllers.js";
|
|
|
|
|
import { createApp } from "./src/app.js";
|
2025-07-25 15:15:14 -07:00
|
|
|
import { initShutdownListener } from "./shutdown.js";
|
2025-04-20 11:29:53 -07:00
|
|
|
import logger from "./utils/logger.js";
|
|
|
|
|
import { fileURLToPath } from "url";
|
2025-07-25 15:15:14 -07:00
|
|
|
import path from "path";
|
|
|
|
|
import fs from "fs";
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-25 15:33:48 -07:00
|
|
|
import SettingsService from "./src/service/system/settingsService.js";
|
|
|
|
|
import AppSettings from "./src/db/models/AppSettings.js";
|
2025-04-20 11:29:53 -07:00
|
|
|
|
|
|
|
|
const SERVICE_NAME = "Server";
|
2025-05-19 15:04:58 -07:00
|
|
|
|
2025-04-20 11:29:53 -07:00
|
|
|
const startApp = async () => {
|
2025-07-25 15:15:14 -07:00
|
|
|
// FE path
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
const openApiSpec = JSON.parse(fs.readFileSync(path.join(__dirname, "openapi.json"), "utf8"));
|
|
|
|
|
const frontendPath = path.join(__dirname, "public");
|
2025-05-08 13:11:51 -07:00
|
|
|
// Create services
|
|
|
|
|
const settingsService = new SettingsService(AppSettings);
|
|
|
|
|
const appSettings = settingsService.loadSettings();
|
|
|
|
|
|
2025-07-25 15:15:14 -07:00
|
|
|
// Initialize services
|
|
|
|
|
const services = await initializeServices(appSettings, settingsService);
|
2025-07-23 13:41:10 -07:00
|
|
|
|
2025-07-25 15:15:14 -07:00
|
|
|
// Initialize controllers
|
|
|
|
|
const controllers = initializeControllers(services);
|
2025-06-06 14:05:59 +08:00
|
|
|
|
2025-07-25 15:15:14 -07:00
|
|
|
const app = createApp({
|
|
|
|
|
services,
|
|
|
|
|
controllers,
|
2025-06-08 09:01:30 +08:00
|
|
|
appSettings,
|
2025-07-25 15:15:14 -07:00
|
|
|
frontendPath,
|
|
|
|
|
openApiSpec,
|
2025-07-24 13:50:21 -07:00
|
|
|
});
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-05-09 09:33:35 -07:00
|
|
|
const port = appSettings.port || 52345;
|
2025-07-25 15:15:14 -07:00
|
|
|
const server = app.listen(port, () => {
|
2025-05-09 09:33:35 -07:00
|
|
|
logger.info({ message: `Server started on port:${port}` });
|
2025-04-20 11:29:53 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-25 15:15:14 -07:00
|
|
|
initShutdownListener(server, services);
|
2025-04-20 11:29:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
startApp().catch((error) => {
|
|
|
|
|
logger.error({
|
|
|
|
|
message: error.message,
|
|
|
|
|
service: SERVICE_NAME,
|
|
|
|
|
method: "startApp",
|
|
|
|
|
stack: error.stack,
|
|
|
|
|
});
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|