Skip to content

Commit

Permalink
Merge pull request #1453 from dappnode/pablo/fix-test-api
Browse files Browse the repository at this point in the history
Add post endpoints to Test API
  • Loading branch information
pablomendezroyo committed Apr 17, 2023
2 parents ddd2acd + 4faae91 commit 5962d4d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/dappmanager/src/api/startTestApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function startTestApi(): http.Server {
try {
req.query[key] = JSON.parse(value);
} catch (e) {
// Do nothing
res.status(500).send(`Error parsing ${key}: ${e.message}`);
}
}
}
Expand All @@ -35,17 +35,19 @@ export function startTestApi(): http.Server {
const callFn = api[callCasted];

if (typeof callFn === "function") {
app.get(`/${callCasted}`, (req, res) => {
logs.info(`Test API call: ${callCasted}`);
callFn(req.query as never)
.then(result => {
res.send(result);
})
.catch(e => {
logs.error(`Test API ERROR in ${callCasted}: ${e}`);
res.status(500).send(e);
});
});
if (callFn.length > 0) {
app.post(`/${callCasted}`, (req, res) => {
callFn(req.body as never)
.then(data => res.send(data))
.catch(e => res.status(500).send(e.message));
});
} else {
app.get(`/${callCasted}`, (req, res) => {
callFn(req.query as never)
.then(data => res.send(data))
.catch(e => res.status(500).send(e.message));
});
}
}
}

Expand Down

0 comments on commit 5962d4d

Please sign in to comment.