From 8e4874bbf0b9b6f63adb7754ce6aea46224219b5 Mon Sep 17 00:00:00 2001 From: Dunemask Date: Sat, 14 Aug 2021 21:42:17 -0600 Subject: [PATCH] Fixed config flow & moved Nodemon config to pkg --- docker-compose.yml | 2 +- package.json | 14 ++++++++++++++ src/api/storage.js | 1 - src/api/user.js | 2 +- src/config.json | 3 +-- src/routes/stash-route.js | 13 ++++++++----- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 627ccd0..ac13a1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: - "52001:52001" environment: - ALEXANDRIA_DATABASE_PASSWORD=${ALEXANDRIA_DATABASE_PASSWORD} - + - CAIRO_URL=http://cairo.dunestorm.net:52000 alexandria.dunestorm.net: image: mongo environment: diff --git a/package.json b/package.json index 7eb3c76..1a81d67 100644 --- a/package.json +++ b/package.json @@ -28,5 +28,19 @@ "multer": "^1.4.2", "path": "^0.12.7", "rimraf": "^3.0.2" + }, + "nodemonConfig": { + "restartable": "rs", + "ignore": [ + ".git", + "./src/uploads/", + "./src/zips/" + ], + "verbose": true, + "ext": "js,json", + "signal": "SIGINT", + "env": { + "CAIRO_URL": "http://localhost:52000" + } } } diff --git a/src/api/storage.js b/src/api/storage.js index 190adf2..0468789 100644 --- a/src/api/storage.js +++ b/src/api/storage.js @@ -100,7 +100,6 @@ function createUser(cairoId) { function getUserByCairoId(cairoId) { return users.findOne({ cairoId }).then((user) => { - console.log("FOUND vvvv", user); if (!user) return createUser(cairoId); return user; }); diff --git a/src/api/user.js b/src/api/user.js index 5ac33f6..a7d7993 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -34,7 +34,7 @@ function deleteFiles(cairoId, targetFiles) { try { fremove(file.path); } catch (e) { - console.error("Error Deleting File", file.name, "\nPath:", file.path); + console.error("Error deleting file ", file.name, "\nPath:", file.path); deleteFails.push(`${file._id}`); } }); diff --git a/src/config.json b/src/config.json index 3abd598..8b03ab1 100644 --- a/src/config.json +++ b/src/config.json @@ -9,7 +9,6 @@ "Server": { "Port": 52001, "Debug": false, - "BodyLimit": "5mb", - "authServer": "http://cairo.dunestorm.net:52000/api/user/data" + "BodyLimit": "5mb" } } diff --git a/src/routes/stash-route.js b/src/routes/stash-route.js index 25f8b52..ba94d25 100644 --- a/src/routes/stash-route.js +++ b/src/routes/stash-route.js @@ -13,12 +13,11 @@ const cairoMiddleware = (req, res, next) => { if (req.token == null) return next(); else axios - .get(config.Server.authServer, { + .get(`${process.env.CAIRO_URL}/user/data`, { headers: { authorization: `Bearer ${req.token}` }, }) .then((authRes) => { - if (authRes.status !== 200) return res.sendStatus(authres.status); - if (authRes.data != null && authRes.data.id != null) { + if (authRes.data && authRes.data.id) { asUser.load(authRes.data.id).then((user) => { req.user = user; next(); @@ -26,8 +25,12 @@ const cairoMiddleware = (req, res, next) => { } else res.status(500).json(authRes.data); }) .catch((e) => { - if (e.response != null) res.sendStatus(e.response.status); - else res.sendStatus(500); + if (e.response) + return res + .status(401) + .send(`Auth server responded with: ${e.response.status}`); + console.error(e); + res.sendStatus(500); }); };