aboutsummaryrefslogtreecommitdiff
path: root/src/app.js
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-05-28 18:52:56 +0200
committerHampusM <hampus@hampusmat.com>2021-05-28 18:52:56 +0200
commit5ee8a02ff03200ef9d9e1639242f93c9be930b04 (patch)
treee4d6dc97ea9ff3abc40368f24207f1ee06c3e28b /src/app.js
parent06f028bf5aefba7d93a7a00373ea820f4537bfd3 (diff)
Cleaned up & added a couple of Eslint rules
Diffstat (limited to 'src/app.js')
-rw-r--r--src/app.js25
1 files changed, 11 insertions, 14 deletions
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");