Log incoming requests and add 404 handler for webhook server

This commit is contained in:
Peter Steinberger
2025-11-24 13:04:47 +01:00
parent efe0a76703
commit f7a7b1b29e

View File

@@ -328,6 +328,12 @@ async function startWebhook(
// Twilio sends application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
app.use((req, _res, next) => {
if (verbose) {
console.log(chalk.gray(`REQ ${req.method} ${req.url}`));
}
next();
});
app.post(path, async (req: Request, res: Response) => {
const { From, To, Body, MessageSid } = req.body ?? {};
@@ -365,6 +371,10 @@ async function startWebhook(
res.type('text/xml').send('<Response></Response>');
});
app.use((req, res) => {
res.status(404).send('warelay webhook: not found');
});
return new Promise<void>((resolve) => {
app.listen(port, () => {
console.log(`📥 Webhook listening on http://localhost:${port}${path}`);