mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
- Add JSDoc comments across frontend and backend modules - Improve code readability and maintainability with consistent documentation style - Document Electron IPC handlers, UI utilities, and theme system - Add missing function/class documentation in theme loader and app services - Minor structural improvements and cleanup across Electron main process modules - Minor fixes on variable names
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
const express = require("express");
|
|
const path = require("path");
|
|
const { logger, logSessionEnd } = require("./logger");
|
|
const config = require("../config");
|
|
const { rateLimit } = require("./helpers/rateLimit.helpers");
|
|
|
|
const app = express();
|
|
|
|
// Middlewares
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
app.use(express.static(path.join(__dirname, "../public")));
|
|
|
|
// Routes
|
|
app.use("/download", require("./routes/download.route"));
|
|
app.use("/info", require("./routes/info.route"));
|
|
app.get("/", rateLimit, (req, res) => {
|
|
res.sendFile(path.join(__dirname, "../public/index.html"));
|
|
});
|
|
|
|
/**
|
|
* Initializes and starts the Express HTTP server.
|
|
*
|
|
* - Binds the server to `config.applicationPort`
|
|
* - Resolves with the HTTP server instance on successful startup
|
|
* - Rejects on server binding or runtime errors
|
|
* - Registers SIGINT/SIGTERM handlers for graceful shutdown
|
|
*/
|
|
async function startServer() {
|
|
return new Promise((resolve, reject) => {
|
|
const server = app.listen(config.applicationPort, () => {
|
|
logger.info(`Express server ready at http://localhost:${config.applicationPort}`);
|
|
resolve(server);
|
|
});
|
|
|
|
server.on("error", (err) => {
|
|
logger.error("Express server error:", err);
|
|
reject(err);
|
|
});
|
|
|
|
/**
|
|
* Clean exit function
|
|
* - Stop Log
|
|
* - Stop Express Server
|
|
* - Stop Electron App
|
|
*/
|
|
const gracefulExit = () => {
|
|
logSessionEnd();
|
|
server.close(() => {
|
|
logger.info("Express server closed cleanly.");
|
|
process.exit();
|
|
});
|
|
};
|
|
|
|
process.on("SIGINT", gracefulExit);
|
|
process.on("SIGTERM", gracefulExit);
|
|
});
|
|
}
|
|
|
|
module.exports = { startServer }; |