2023-08-10 17:55:04 +00:00
|
|
|
import express from "express";
|
2023-08-10 18:36:32 +00:00
|
|
|
import bodyParser from "body-parser";
|
2023-08-11 14:21:24 +00:00
|
|
|
import logger from "./logger.mjs";
|
2023-08-10 17:55:04 +00:00
|
|
|
const app = express()
|
|
|
|
const port = 4000
|
2023-08-10 18:36:32 +00:00
|
|
|
app.use(bodyParser.json())
|
|
|
|
app.post('/api', (req,res) => {
|
|
|
|
console.log("webhook received:")
|
|
|
|
console.dir(req.body.body.note.text)
|
|
|
|
res.sendStatus(200)
|
2023-08-10 17:55:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`listening on port ${port}`)
|
2023-08-11 14:21:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
process.on('uncaughtException', (err) => {
|
|
|
|
// log the exception
|
|
|
|
logger.fatal(err, 'uncaught exception detected');
|
|
|
|
// shutdown the server gracefully
|
|
|
|
server.close(() => {
|
|
|
|
process.exit(1); // then exit
|
|
|
|
});
|
|
|
|
|
|
|
|
// If a graceful shutdown is not achieved after 1 second,
|
|
|
|
// shut down the process completely
|
|
|
|
setTimeout(() => {
|
|
|
|
process.abort(); // exit immediately and generate a core dump file
|
|
|
|
}, 1000).unref()
|
|
|
|
process.exit(1);
|
|
|
|
});
|