fix: don't shadow the healthcheck endpoint... (#1709)

This commit is contained in:
zk
2026-07-05 23:15:25 +01:00
committed by GitHub
parent b57ca5670c
commit 2042738974
2 changed files with 19 additions and 14 deletions
+4 -1
View File
@@ -5,7 +5,7 @@ import { Client, type CommandInteraction, Intents, type SelectMenuInteraction }
import { Env, ServerConfig } from "./config";
import { handleIsCommand } from "./interaction-handlers/handle-is-command";
import { GetUserAndTokenForDiscordID } from "./query/user-map";
import { app } from "./server/server";
import { app, MountFallbackHandlers } from "./server/server";
import { ClosePgConnection } from "./services/pg/db";
import { RegisterSlashCommands } from "./slash-commands/register";
import { VERSION_PRETTY } from "./version";
@@ -101,6 +101,9 @@ void (async () => {
log.info(`Logged in successfully to ${client.guilds.cache.size} guilds.`);
// Mount the 404 + error fallbacks last.
MountFallbackHandlers();
// Mount our express server.
const server = app.listen(Env.PORT);
+15 -13
View File
@@ -159,18 +159,6 @@ app.post("/webhook", ValidateWebhookRequest, async (req, res) => {
return res.sendStatus(statusCode);
});
/**
* 404 Handler. If something gets to this point, they haven't matched with anything.
*
* @name ALL *
*/
app.all("*", (_req, res) =>
res.status(404).json({
success: false,
description: "Nothing found here.",
}),
);
interface ExpressJSONErr extends SyntaxError {
status: number;
message: string;
@@ -209,6 +197,20 @@ const MainExpressErrorHandler: express.ErrorRequestHandler = (err, req, res, _ne
});
};
app.use(MainExpressErrorHandler);
export function MountFallbackHandlers(): void {
/**
* 404 Handler. If something gets to this point, they haven't matched with anything.
*
* @name ALL *
*/
app.all("*", (_req, res) =>
res.status(404).json({
success: false,
description: "Nothing found here.",
}),
);
app.use(MainExpressErrorHandler);
}
log.info(`Starting express server on port ${Env.PORT}.`);