From 5ee8a02ff03200ef9d9e1639242f93c9be930b04 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 28 May 2021 18:52:56 +0200 Subject: Cleaned up & added a couple of Eslint rules --- src/app.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/app.js') diff --git a/src/app.js b/src/app.js index 57f0ca1..b05bbcf 100644 --- a/src/app.js +++ b/src/app.js @@ -13,22 +13,23 @@ const settings_keys = Object.keys(settings); const mandatory_settings = [ "host", "port", "title", "about", "base_dir" ]; -const mandatory_not_included = settings_keys.filter(x => !mandatory_settings.includes(x)); +// Make sure that all the required settings are present const settings_not_included = mandatory_settings.filter(x => !settings_keys.includes(x)); - if(settings_not_included.length !== 0) { - console.log(`Error: settings.yml is missing ${(mandatory_not_included.length > 1) ? "keys" : "key"}:`); + console.log(`Error: settings.yml is missing ${(settings_not_included.length > 1) ? "keys" : "key"}:`); console.log(settings_not_included.join(", ")); exit(1); } + +// Make sure that there's not an excessive amount of settings +const mandatory_not_included = settings_keys.filter(x => !mandatory_settings.includes(x)); if(mandatory_not_included.length !== 0) { console.log(`Error: settings.yml includes ${(mandatory_not_included.length > 1) ? "pointless keys" : "a pointless key"}:`); console.log(mandatory_not_included.join(", ")); exit(1); } -const dist_dir = path.join(__dirname, "/../dist"); - +// Make sure that the base directory specified in the settings actually exists try { fs.readdirSync(settings["base_dir"]); } @@ -37,6 +38,8 @@ catch { exit(1); } +const dist_dir = path.join(__dirname, "/../dist"); + fastify.setNotFoundHandler({ preValidation: (req, reply, done) => done(), preHandler: (req, reply, done) => done() @@ -45,21 +48,15 @@ fastify.setNotFoundHandler({ reply.send("404: Not found"); }); - fastify.addContentTypeParser("application/x-git-upload-pack-request", (req, payload, done) => done(null, payload)); -fastify.register(fastify_static, { root: dist_dir }) +fastify.register(fastify_static, { root: dist_dir }); fastify.register(api, { prefix: "/api/v1", config: { settings: settings } }); fastify.route({ method: "GET", path: "/", - handler: (req, reply) => - { - console.log("AAAA faan"); - console.log(dist_dir) - reply.sendFile("app.html"); - } + handler: (req, reply) => reply.sendFile("app.html") }); fastify.route({ @@ -124,7 +121,7 @@ fastify.register((fastify_repo, opts, done) => { if(!req.query.service) { reply.code(403).send("Missing service query parameter\n"); - return + return; } else if(req.query.service !== "git-upload-pack") { reply.code(403).send("Access denied!\n"); -- cgit v1.2.3-18-g5258