Skip to content

Commit

Permalink
Merge pull request #11 from muneeb706/feature-improvements
Browse files Browse the repository at this point in the history
Update dependencies and fix middleware arrow function #4
  • Loading branch information
muneeb706 authored Feb 17, 2024
2 parents ea7e652 + 53c8a49 commit 101780e
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 179 deletions.
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const path = require("path");
const logger = require("morgan");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const session = require("express-session");
const passport = require("passport");
const flash = require("connect-flash");
const MongoStore = require("connect-mongo")(session);
const MongoStore = require("connect-mongo");
const favicon = require("serve-favicon");

const index = require("./routes/index");
const admin = require("./routes/admin");
const employee = require("./routes/employee");
const manager = require("./routes/manager");
const db = require("./db");

expressValidator = require("express-validator");

Expand Down Expand Up @@ -65,8 +65,8 @@ app.use(
secret: "mysupersecret",
resave: false,
saveUninitialized: false,
store: new MongoStore({
mongooseConnection: mongoose.connection,
store: MongoStore.create({
client: db.getConnection().getClient(),
}),
cookie: { maxAge: 180 * 60 * 1000 },
})
Expand Down
30 changes: 11 additions & 19 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,34 @@
*
*/

/**
* Module dependencies.
*/

const app = require("../app");
const http = require("http");
const db = require("../db");

/**
* Create HTTP server.
*/

const server = http.createServer(app);
let server;

db.connect()
.then(() => {
console.log("Database connected");

const app = require("../app");
const http = require("http");
/**
* Listen on provided port, on all network interfaces.
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || "3000");
/**
* Create HTTP server.
*/
server = http.createServer(app);
server.listen(port);
server.on("error", onError);
server.on("listening", onListening);
app.set("port", port);
})
.catch((err) => {
console.error("Database connection error", err);
process.exit(1);
});

/**
* Get port from environment and store in Express.
*/

let port = normalizePort(process.env.PORT || "3000");
app.set("port", port);

/**
* Normalize a port into a number, string, or false.
Expand Down
9 changes: 7 additions & 2 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const connect = (opts = {}) => {
default:
url = process.env.DB_URL;
}



return mongoose.connect(url, {
...opts,
useNewUrlParser: true,
Expand All @@ -27,4 +28,8 @@ const close = () => {
return mongoose.connection.close();
};

module.exports = { connect, close };
const getConnection = () => {
return mongoose.connection;
};

module.exports = { connect, close, getConnection };
Loading

0 comments on commit 101780e

Please sign in to comment.