Fixed config flow & moved Nodemon config to pkg

This commit is contained in:
Dunemask 2021-08-14 21:42:17 -06:00
parent e6009c5ac0
commit 8e4874bbf0
6 changed files with 25 additions and 10 deletions

View file

@ -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);
});
};