diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts
index c3cfa04aa..d7ba9260d 100644
--- a/src/bundle/Server.ts
+++ b/src/bundle/Server.ts
@@ -16,6 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import morgan from "morgan";
+
process.on("unhandledRejection", console.error);
process.on("uncaughtException", console.error);
@@ -59,6 +61,24 @@ async function main() {
await Config.init();
await Sentry.init(app);
+ const logRequests = process.env["LOG_REQUESTS"] != undefined;
+ if (logRequests) {
+ app.use(
+ morgan("combined", {
+ skip: (req, res) => {
+ let skip = !(
+ process.env["LOG_REQUESTS"]?.includes(
+ res.statusCode.toString(),
+ ) ?? false
+ );
+ if (process.env["LOG_REQUESTS"]?.charAt(0) == "-")
+ skip = !skip;
+ return skip;
+ },
+ }),
+ );
+ }
+
await new Promise((resolve) =>
server.listen({ port }, () => resolve(undefined)),
);
diff --git a/src/cdn/Server.ts b/src/cdn/Server.ts
index a16b8ed6a..a4574c978 100644
--- a/src/cdn/Server.ts
+++ b/src/cdn/Server.ts
@@ -24,6 +24,7 @@ import guildProfilesRoute from "./routes/guild-profiles";
import iconsRoute from "./routes/role-icons";
import { CORS } from "../api/middlewares/CORS";
import { BodyParser } from "../api/middlewares/BodyParser";
+import morgan from "morgan";
export type CDNServerOptions = ServerOptions;
@@ -39,6 +40,24 @@ export class CDNServer extends Server {
await Config.init();
await Sentry.init(this.app);
+ const logRequests = process.env["LOG_REQUESTS"] != undefined;
+ if (logRequests) {
+ this.app.use(
+ morgan("combined", {
+ skip: (req, res) => {
+ let skip = !(
+ process.env["LOG_REQUESTS"]?.includes(
+ res.statusCode.toString(),
+ ) ?? false
+ );
+ if (process.env["LOG_REQUESTS"]?.charAt(0) == "-")
+ skip = !skip;
+ return skip;
+ },
+ }),
+ );
+ }
+
this.app.disable("x-powered-by");
this.app.use(CORS);
|