XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

improve: tell user that the WebUI is available (#631)

063adb35
Sainan <sainan@calamity.inc>
提交于

代码差异

3 个文件 +23 -22
Modified src/app.ts +0 -5
@@ -13,11 +13,6 @@ import { customRouter } from "@/src/routes/custom";
13 13 import { dynamicController } from "@/src/routes/dynamic";
14 14 import { statsRouter } from "@/src/routes/stats";
15 15 import { webuiRouter } from "@/src/routes/webui";
16 import { connectDatabase } from "@/src/services/mongoService";
17 import { registerLogFileCreationListener } from "@/src/utils/logger";
18
19 void registerLogFileCreationListener();
20 void connectDatabase();
21 16
22 17 const app = express();
23 18
Modified src/index.ts +22 -14
@@ -7,21 +7,29 @@ import https from "https";
7 7 import fs from "node:fs";
8 8 import { app } from "./app";
9 9 import { config } from "./services/configService";
10 //const morgan = require("morgan");
11 //const bodyParser = require("body-parser");
10 import { connectDatabase } from "@/src/services/mongoService";
11 import { registerLogFileCreationListener } from "@/src/utils/logger";
12 12
13 const options = {
14 key: fs.readFileSync("static/certs/key.pem"),
15 cert: fs.readFileSync("static/certs/cert.pem")
16 };
13 registerLogFileCreationListener();
17 14
18 const httpPort = config.httpPort || 80;
19 const httpsPort = config.httpsPort || 443;
15 void (async (): Promise<void> => {
16 await connectDatabase();
20 17
21 // const server = http.createServer(app).listen(80);
22 http.createServer(app).listen(httpPort, () => logger.info("HTTP server started on port " + httpPort));
23 const server = https.createServer(options, app);
24 server.listen(httpsPort, () => logger.info("HTTPS server started on port " + httpsPort));
18 const httpPort = config.httpPort || 80;
19 const httpsPort = config.httpsPort || 443;
20 const options = {
21 key: fs.readFileSync("static/certs/key.pem"),
22 cert: fs.readFileSync("static/certs/cert.pem")
23 };
25 24
26 // server.keepAliveTimeout = 60 * 1000 + 1000;
27 // server.headersTimeout = 60 * 1000 + 2000;
25 http.createServer(app).listen(httpPort, () => {
26 logger.info("HTTP server started on port " + httpPort);
27 https.createServer(options, app).listen(httpsPort, () => {
28 logger.info("HTTPS server started on port " + httpsPort);
29
30 logger.info(
31 "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
32 );
33 });
34 });
35 })();
Modified src/services/mongoService.ts +1 -3
@@ -8,7 +8,7 @@ if (url === undefined) {
8 8 throw new Error("MONGODB_URL not found. Make sure you have a .env file in the root of the project!");
9 9 }
10 10
11 const connectDatabase = async () => {
11 export const connectDatabase = async (): Promise<void> => {
12 12 try {
13 13 await mongoose.connect(`${url}`);
14 14 logger.info("Connected to MongoDB");
@@ -18,5 +18,3 @@ const connectDatabase = async () => {
18 18 }
19 19 }
20 20 };
21
22 export { connectDatabase };