Log incoming requests and add 404 handler for webhook server
This commit is contained in:
10
src/index.ts
10
src/index.ts
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user