feat(listenbrainz): Use end-of-string token and wildcard route to better log malformed LZ endpoint routes

This commit is contained in:
FoxxMD 2025-11-03 16:08:17 +00:00
parent 4ee503655c
commit a5f6aaa7c0

View file

@ -17,7 +17,7 @@ export const setupLZEndpointRoutes = (app: ExpressWithAsync, parentLogger: Logge
const nonEmptyCheck = nonEmptyBody(logger, 'LZ Endpoint');
const webhookIngress = new LZEndpointNotifier(logger);
app.useAsync(/(\/api\/listenbrainz.*)|(\/1\/submit-listens)/,
app.useAsync(/(\/api\/listenbrainz.*)|(\/1\/submit-listens\/?$)/,
async function (req, res, next) {
// track request before parsing body to ensure we at least log that something is happening
// (in the event body parsing does not work or request is not POST/PATCH)
@ -59,5 +59,9 @@ export const setupLZEndpointRoutes = (app: ExpressWithAsync, parentLogger: Logge
user_name: "Multi-Scrobbler"
})
});
app.useAsync(/\/1\/.*/, async function (req, res) {
logger.warn(`Received what looks like a Listenbrainz Endpoint request but it was to an invalid URL route: ${req.originalUrl}\nMake sure base URL path to MS endpoint is correct.`);
res.status(404);
});
}