micro365/index.mjs

43 lines
1.1 KiB
JavaScript
Raw Normal View History

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-11 14:30:47 +00:00
import pinoHTTP from 'pino-http'
2023-08-11 14:52:17 +00:00
import start from "./start.mjs";
2023-08-12 09:43:37 +00:00
import receiveMention from "./social-interaction/receiveMention.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())
2023-08-11 14:30:47 +00:00
app.use(
pinoHTTP({
logger,
})
)
2023-08-10 18:36:32 +00:00
app.post('/api', (req,res) => {
2023-08-13 13:00:24 +00:00
//receiveMention(req.body)
logger.info({body:req.body.body},"webhook received!")
//logger.info(req.body.body)
//logger.info("webhook received:",req.body.body.note.text)
2023-08-10 18:36:32 +00:00
res.sendStatus(200)
2023-08-10 17:55:04 +00:00
})
app.listen(port, () => {
2023-08-11 14:52:17 +00:00
logger.trace(`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
2023-08-11 14:52:17 +00:00
app.close(() => {
2023-08-11 14:21:24 +00:00
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);
2023-08-11 14:52:17 +00:00
});
start()