aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/index.js b/index.js
index 2c7a373..558d7d0 100644
--- a/index.js
+++ b/index.js
@@ -21,20 +21,31 @@ app.all('/:path*', async (req, res) => {
const path = req.params.path.split('/')[0];
if (!path || path.length === 0) {
res.status(400);
- res.send('Empty endpoint.');
+ return res.send('Empty endpoint.');
}
const endpoint = await models.endpoints.findOne({name: path});
if (!endpoint) {
res.status(400);
- res.send('No such endpoint.');
+ return res.send('No such endpoint.');
}
+ const secretsList = await models.endpoints.find();
+ if (!secretsList) {
+ res.status(500);
+ return res.send('Failed to fetch secrets from the database.');
+ }
+
+ const secrets = secretsList.reduce((prev, cur) => ({
+ ...prev,
+ [cur.key]: cur.value
+ }), {});
+
console.info(`${chalk.green(req.path)}, running endpoint "${chalk.yellow(endpoint.name)}".`);
const {code} = endpoint;
try {
const func = requireFromString(code);
- func(req, res);
+ func(req, res, secrets);
} catch (err) {
res.status(500);
console.error(chalk.red(`Error in endpoint ${endpoint.name}! Details below.`));