From 063adb3519e11925b16f3ced0937249ecf9f7122 Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 23 Dec 2024 22:48:16 +0100 Subject: [PATCH] improve: tell user that the WebUI is available (#631) --- src/app.ts | 5 ----- src/index.ts | 36 ++++++++++++++++++++++-------------- src/services/mongoService.ts | 4 +--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/app.ts b/src/app.ts index 514d4336..4d02f79e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,11 +13,6 @@ import { customRouter } from "@/src/routes/custom"; import { dynamicController } from "@/src/routes/dynamic"; import { statsRouter } from "@/src/routes/stats"; import { webuiRouter } from "@/src/routes/webui"; -import { connectDatabase } from "@/src/services/mongoService"; -import { registerLogFileCreationListener } from "@/src/utils/logger"; - -void registerLogFileCreationListener(); -void connectDatabase(); const app = express(); diff --git a/src/index.ts b/src/index.ts index e82fd2fe..6bb6b6f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,21 +7,29 @@ import https from "https"; import fs from "node:fs"; import { app } from "./app"; import { config } from "./services/configService"; -//const morgan = require("morgan"); -//const bodyParser = require("body-parser"); +import { connectDatabase } from "@/src/services/mongoService"; +import { registerLogFileCreationListener } from "@/src/utils/logger"; -const options = { - key: fs.readFileSync("static/certs/key.pem"), - cert: fs.readFileSync("static/certs/cert.pem") -}; +registerLogFileCreationListener(); -const httpPort = config.httpPort || 80; -const httpsPort = config.httpsPort || 443; +void (async (): Promise => { + await connectDatabase(); -// const server = http.createServer(app).listen(80); -http.createServer(app).listen(httpPort, () => logger.info("HTTP server started on port " + httpPort)); -const server = https.createServer(options, app); -server.listen(httpsPort, () => logger.info("HTTPS server started on port " + httpsPort)); + const httpPort = config.httpPort || 80; + const httpsPort = config.httpsPort || 443; + const options = { + key: fs.readFileSync("static/certs/key.pem"), + cert: fs.readFileSync("static/certs/cert.pem") + }; -// server.keepAliveTimeout = 60 * 1000 + 1000; -// server.headersTimeout = 60 * 1000 + 2000; + http.createServer(app).listen(httpPort, () => { + logger.info("HTTP server started on port " + httpPort); + https.createServer(options, app).listen(httpsPort, () => { + logger.info("HTTPS server started on port " + httpsPort); + + logger.info( + "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort) + ); + }); + }); +})(); diff --git a/src/services/mongoService.ts b/src/services/mongoService.ts index a90b6f8e..ef6de535 100644 --- a/src/services/mongoService.ts +++ b/src/services/mongoService.ts @@ -8,7 +8,7 @@ if (url === undefined) { throw new Error("MONGODB_URL not found. Make sure you have a .env file in the root of the project!"); } -const connectDatabase = async () => { +export const connectDatabase = async (): Promise => { try { await mongoose.connect(`${url}`); logger.info("Connected to MongoDB"); @@ -18,5 +18,3 @@ const connectDatabase = async () => { } } }; - -export { connectDatabase };