feat: play verb url support single or array list url (#158)

* feat: update time-series 0.11.12

* feat: support play verb url in plain text or array

* fix: review comment

Co-authored-by: Dave Horton <daveh@beachdognet.com>
This commit is contained in:
xquanluu
2022-08-25 15:09:48 +07:00
committed by GitHub
parent 4f0439dad9
commit 127432f2ec
14 changed files with 323 additions and 20 deletions

View File

@@ -20,11 +20,7 @@ app.use(express.json());
app.all('/', (req, res) => {
console.log(req.body, 'POST /');
const key = req.body.from
if (!json_mapping.has(key)) return res.sendStatus(404);
const retData = JSON.parse(json_mapping.get(key));
console.log(retData, `${req.method} /`);
addRequestToMap(key, req, hook_mapping);
return res.json(retData);
return getJsonFromMap(key, req, res);
});
app.post('/appMapping', (req, res) => {
@@ -52,6 +48,24 @@ app.post('/actionHook', (req, res) => {
return res.sendStatus(200);
});
/*
* customHook
* For the hook to return
*/
app.all('/customHook', (req, res) => {
let key = `${req.body.from}_customHook`;;
console.log(req.body, `POST /customHook`);
return getJsonFromMap(key, req, res);
});
app.post('/customHookMapping', (req, res) => {
let key = `${req.body.from}_customHook`;
console.log(req.body, `POST /customHookMapping`);
json_mapping.set(key, req.body.data);
return res.sendStatus(200);
});
// Fetch Requests
app.get('/requests/:key', (req, res) => {
let key = req.params.key;
@@ -77,6 +91,14 @@ app.get('/lastRequest/:key', (req, res) => {
* private function
*/
function getJsonFromMap(key, req, res) {
if (!json_mapping.has(key)) return res.sendStatus(404);
const retData = JSON.parse(json_mapping.get(key));
console.log(retData, ` Response to ${req.method} ${req.url}`);
addRequestToMap(key, req, hook_mapping);
return res.json(retData);
}
function addRequestToMap(key, req, map) {
let headers = new Map()
for(let i = 0; i < req.rawHeaders.length; i++) {