app.ts (1070B)
1 import express from "express"; 2 import twilio from "twilio"; 3 import log from "./log.ts"; 4 import message from "./message.ts"; 5 import voice from "./voice.ts"; 6 import configure from "./configure.ts"; 7 import health from "./health.ts"; 8 import listen from "./listen.ts"; 9 10 const app = express(); 11 12 const validate = !!process.env.TWILIO_AUTH_TOKEN; 13 14 app.set("trust proxy", true); 15 16 app.use(express.urlencoded({ extended: false })); 17 18 app.post("/voice", twilio.webhook({ validate }), voice); 19 20 app.post("/message", twilio.webhook({ validate }), message); 21 22 app.post("/configure", configure); 23 24 app.get("/health", health); 25 26 const port: number = parseInt(process.env.PORT || "3000", 10); 27 28 const server = app.listen(port, listen); 29 30 process.on("SIGINT", () => { 31 log("INFO", "Received SIGINT, shutting down gracefully"); 32 server.close(() => { 33 log("INFO", "Server closed"); 34 process.exit(0); 35 }); 36 }); 37 38 process.on("SIGTERM", () => { 39 log("INFO", "Received SIGTERM, shutting down gracefully"); 40 server.close(() => { 41 log("INFO", "Server closed"); 42 process.exit(0); 43 }); 44 });