feat: Add optional http logging in production (#2183)

* feat: Add optional http logging in production
closes #2174

* Update app.js
This commit is contained in:
Tom Moor
2021-06-05 15:19:54 -07:00
committed by GitHub
parent f517a2cecb
commit 5c7f2cf164
4 changed files with 19 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
// @flow
import * as Sentry from "@sentry/node";
import debug from "debug";
import Koa from "koa";
import compress from "koa-compress";
import helmet, {
@@ -21,6 +22,7 @@ import updates from "./utils/updates";
const app = new Koa();
const isProduction = process.env.NODE_ENV === "production";
const isTest = process.env.NODE_ENV === "test";
const log = debug("http");
// Construct scripts CSP based on services in use by this installation
const defaultSrc = ["'self'"];
@@ -105,11 +107,16 @@ if (isProduction) {
})
)
);
app.use(logger());
app.use(mount("/emails", emails));
}
// redirect routing logger to optional "http" debug
app.use(
logger((str, args) => {
log(str);
})
);
// catch errors in one place, automatically set status and response headers
onerror(app);