diff options
| author | Jan Tuomi <jan.tuomi@eficode.com> | 2018-07-12 15:23:25 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@eficode.com> | 2018-07-12 15:23:25 +0300 |
| commit | d965ac8bb00e443c6c9ce72674b72edcaa3e9ecc (patch) | |
| tree | 4bdff2f6a363675ddb6857aa374f84596507ce44 /index.js | |
| parent | c6673a1146567c397e34a49d5c0a0b57a4b56256 (diff) | |
Implement secrets
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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.`)); |
