aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@eficode.com>2018-07-12 14:20:28 +0300
committerJan Tuomi <jan.tuomi@eficode.com>2018-07-12 14:20:28 +0300
commit0f28ca26c3a0b8b4d4e15f742be7ef4ec40c590e (patch)
tree492378645eb9a4c4d20a4fc192a26fe4fd7e99a9 /index.js
parentd4a8d80bc2c7b60b26e1e62e8287257972c2febd (diff)
Fix xo offenses
Diffstat (limited to 'index.js')
-rw-r--r--index.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/index.js b/index.js
index 6804fbe..2c7a373 100644
--- a/index.js
+++ b/index.js
@@ -1,19 +1,20 @@
require('dotenv').config();
-const chalk = require('chalk');
const path = require('path');
+const chalk = require('chalk');
if (!process.env.MONGO_URL) {
throw new Error('No MONGO_URL set in .env!');
}
const db = require('monk')(process.env.MONGO_URL);
-const models = require('./models')(db);
const express = require('express');
+
const app = express();
const requireFromString = require('require-from-string');
+const models = require('./models')(db);
-app.get('/', function(req, res) {
- res.sendFile(path.join(__dirname + '/frontpage.html'));
+app.get('/', (req, res) => {
+ res.sendFile(path.join(__dirname, '/frontpage.html'));
});
app.all('/:path*', async (req, res) => {
@@ -23,17 +24,17 @@ app.all('/:path*', async (req, res) => {
res.send('Empty endpoint.');
}
- const endpoint = await models.endpoints.findOne({ name: path });
+ const endpoint = await models.endpoints.findOne({name: path});
if (!endpoint) {
res.status(400);
res.send('No such endpoint.');
}
console.info(`${chalk.green(req.path)}, running endpoint "${chalk.yellow(endpoint.name)}".`);
- const code = endpoint.code;
+ const {code} = endpoint;
try {
const func = requireFromString(code);
- const output = func(req, res);
+ func(req, res);
} catch (err) {
res.status(500);
console.error(chalk.red(`Error in endpoint ${endpoint.name}! Details below.`));