summary refs log tree commit diff
path: root/api/src/Server.ts
diff options
context:
space:
mode:
authorThe Arcane Brony <myrainbowdash949@gmail.com>2021-09-18 16:13:15 +0000
committerThe Arcane Brony <myrainbowdash949@gmail.com>2021-09-18 18:13:15 +0200
commitc3fca1c02fb79a4f2daf57469fb42f12224f65fe (patch)
treeb9f46a810e0481c48919305fc5522c29deda6338 /api/src/Server.ts
parentMerge pull request #374 from TheArcaneBrony/dummy-connections-endpoint (diff)
downloadserver-c3fca1c02fb79a4f2daf57469fb42f12224f65fe.tar.xz
Add request logging (with env var: log-requests)
Request logging is enabled when the log-request environment variable is set.
Diffstat (limited to 'api/src/Server.ts')
-rw-r--r--api/src/Server.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/api/src/Server.ts b/api/src/Server.ts
index b9ca3fba..318d7094 100644
--- a/api/src/Server.ts
+++ b/api/src/Server.ts
@@ -11,6 +11,7 @@ import path from "path";
 import { initRateLimits } from "./middlewares/RateLimit";
 import TestClient from "./middlewares/TestClient";
 import { initTranslation } from "./middlewares/Translation";
+import morgan from "morgan";
 
 export interface FosscordServerOptions extends ServerOptions {}
 
@@ -36,6 +37,11 @@ export class FosscordServer extends Server {
 		await Config.init();
 		await initEvent();
 
+		let logRequests = process.env["log-requests"] != undefined;
+		if(logRequests) {
+			this.app.use(morgan("combined"));
+		}
+
 		this.app.use(CORS);
 		this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
 
@@ -65,6 +71,9 @@ export class FosscordServer extends Server {
 		this.app.use(ErrorHandler);
 		TestClient(this.app);
 
+		if(logRequests){
+			console.log("Warning: Request logging is enabled! This will spam your console!\nTo disable this, unset the 'log-requests' environment variable!");
+		}
 		return super.start();
 	}
 }