summary refs log tree commit diff
path: root/src/bundle
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2025-07-02 18:26:58 +0200
committerRory& <root@rory.gay>2025-07-06 18:03:17 +0200
commitd2015f06bedf481efd3692bb5da2a43545682942 (patch)
treecca1dd33b4faa106587cc16063a2e8ce2ca19649 /src/bundle
parentFix opcode 8 (diff)
downloadserver-ts-d2015f06bedf481efd3692bb5da2a43545682942.tar.xz
Consistent request logging
Diffstat (limited to 'src/bundle')
-rw-r--r--src/bundle/Server.ts20
1 files changed, 20 insertions, 0 deletions
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)), );