Skip to content

Commit

Permalink
adjuted error logging and moved db dir ensurance to setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rastenis committed Jul 25, 2019
1 parent 9c1ef7d commit 52a52f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 2 additions & 0 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const fs = require("fs-extra");
let config = require("./config/configExample.json");
let passportKeys = require("./config/passportKeysExample.json");

fs.ensureDirSync("./db/");

if (process.argv[2]=="--headless") {
// saving defaults
fs.copySync('./config/configExample.json', './config/config.json')
Expand Down
24 changes: 8 additions & 16 deletions src/external/db.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
const Datastore = require("nedb");
const fs = require("fs-extra");

/*
A single database for user data
*/
let db;
const db = {
users: new Datastore({
filename: "db/users",
autoload: true
})
};

// ensuring folder
fs.ensureDir("db/").then(()=>{
db = {
users: new Datastore({
filename: "db/users",
autoload: true
})
};

// making usernames unique
// making usernames unique
db.users.ensureIndex(
{
fieldName: "email",
Expand All @@ -28,8 +23,5 @@ db.users.ensureIndex(
}
}
);
});



module.exports = db;
module.exports = db;
9 changes: 7 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ app.post("/register", (req, res, next) => {
);
})
.catch(err => {
utils.log(err, 1);
return res.json({
meta: {
error: true,
Expand All @@ -253,7 +254,7 @@ app.post("/logout", (req, res) => {
}

req.logout();

return res.json({
meta: {
error: false,
Expand Down Expand Up @@ -300,8 +301,12 @@ app.patch("/changePassword", (req, res) => {
});
})
.catch(e => {
utils.log(e, 1);
return res.json({
meta: e
meta: {
error: true,
msg: "Internal error. Please try again later!"
}
});
});
});
Expand Down

0 comments on commit 52a52f7

Please sign in to comment.