mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
2 years ago
|
// https://glebbahmutov.com/blog/restart-server/
|
||
|
|
||
|
// const { express } = require("express");
|
||
|
// const { bodyParser } = require("body-parser");
|
||
|
|
||
2 years ago
|
import express from 'express';
|
||
|
import bodyParser from 'body-parser';
|
||
2 years ago
|
|
||
|
let request = [];
|
||
|
|
||
|
async function makeServer() {
|
||
|
const app = express();
|
||
|
app.use(bodyParser.json());
|
||
|
|
||
2 years ago
|
app.get('/hook/all', (req, res) => {
|
||
2 years ago
|
// console.log(request)
|
||
|
res.json(request);
|
||
|
});
|
||
2 years ago
|
app.get('/hook/last', (req, res) => {
|
||
2 years ago
|
if (request.length) {
|
||
|
// console.log(request[request.length - 1])
|
||
|
res.json(request[request.length - 1]);
|
||
|
}
|
||
|
});
|
||
2 years ago
|
app.get('/hook/count', (req, res) => {
|
||
2 years ago
|
// console.log(request.length)
|
||
|
res.json(request.length);
|
||
|
});
|
||
2 years ago
|
app.get('/hook/clear', (req, res) => {
|
||
2 years ago
|
request = [];
|
||
|
res.status(200).end();
|
||
|
});
|
||
|
|
||
2 years ago
|
app.post('/hook', (req, res) => {
|
||
2 years ago
|
request.push(req.body);
|
||
|
// console.log("/hook :: ", req.body) // Call your action on the request here
|
||
|
res.status(200).end(); // Responding is important
|
||
|
});
|
||
|
|
||
2 years ago
|
app.post('/stop', (req, res) => {
|
||
2 years ago
|
process.exit();
|
||
|
});
|
||
|
|
||
|
const port = 9090;
|
||
|
|
||
2 years ago
|
return new Promise(resolve => {
|
||
2 years ago
|
const server = app.listen(port, function () {
|
||
|
const port = server.address().port;
|
||
2 years ago
|
// console.log("Example app listening at port %d", port);
|
||
2 years ago
|
|
||
|
// close the server
|
||
|
const close = () => {
|
||
2 years ago
|
return new Promise(resolve => {
|
||
2 years ago
|
// console.log("closing server");
|
||
2 years ago
|
server.close(resolve);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
resolve({ server, port, close });
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export default makeServer;
|