summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorThe Arcane Brony <myrainbowdash949@gmail.com>2021-09-18 18:43:00 +0000
committerThe Arcane Brony <myrainbowdash949@gmail.com>2021-09-18 20:43:00 +0200
commit76211281ab911070dda58a74130c3665ff07f73e (patch)
tree892188b18cfae4516a3b17175768849639bd7ec8 /api/src
parentAdd request logging (with env var: log-requests) (diff)
downloadserver-76211281ab911070dda58a74130c3665ff07f73e.tar.xz
Add response code white/blacklisting
Diffstat (limited to 'api/src')
-rw-r--r--api/src/Server.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/api/src/Server.ts b/api/src/Server.ts
index 318d7094..bda19db5 100644
--- a/api/src/Server.ts
+++ b/api/src/Server.ts
@@ -1,3 +1,4 @@
+import { OptionsJson } from 'body-parser';
 import "missing-native-js-functions";
 import { Connection } from "mongoose";
 import { Server, ServerOptions } from "lambert-server";
@@ -37,9 +38,27 @@ export class FosscordServer extends Server {
 		await Config.init();
 		await initEvent();
 
+
+		/* 
+		DOCUMENTATION: uses log-requests environment variable
+		
+		# only log 200 and 204
+		log-requests=200 204
+		# log everything except 200 and 204
+		log-requests=-200 204
+		# log all requests
+		log-requests=-
+		*/
+		
 		let logRequests = process.env["log-requests"] != undefined;
 		if(logRequests) {
-			this.app.use(morgan("combined"));
+			this.app.use(morgan("combined", {
+				skip: (req, res) => {
+					var skip = !(process.env["log-requests"]?.includes(res.statusCode.toString()) ?? false);
+					if(process.env["log-requests"]?.charAt(0) == '-') skip = !skip;
+					return skip;
+				}
+			}));
 		}
 
 		this.app.use(CORS);