Consistent request logging
This commit is contained in:
parent
253bc2f255
commit
d2015f06be
@ -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)),
|
||||
);
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user