-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (47 loc) · 1.72 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require("express");
const app = express();
const port = process.env.PORT || 8888;
const expressLayouts = require("express-ejs-layouts");
const methodOverride = require("./middlewares/method_override");
const setCurrentUser = require("./middlewares/set_current_user");
const viewHelpers = require("./middlewares/view_helpers");
const feedController = require("./controllers/feed_controller");
const postController = require("./controllers/post_controller");
const sessionController = require("./controllers/session_controller");
const userController = require("./controllers/user_controller");
const session = require('express-session');
const pgSession = require('connect-pg-simple')(session);
const ensureLoggedIn = require("./middlewares/ensure_logged_in")
// const MemoryStore = require('memorystore')(session);
const db = require("./db");
// configs
app.set("view engine", "ejs");
app.set("layout layout_login", false);
app.use(expressLayouts);
app.use(express.static("public"));
app.use(express.urlencoded({extended: true}));
app.use(methodOverride);
app.use(session({
store: new pgSession({
pool : db, // Connection pool
tableName: "session"
}),
secret: process.env.SESSION_SECRET || "godogsgo",
resave: false,
saveUninitialized: false,
cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 } // 30 days
// Insert express-session options here
}));
app.use(setCurrentUser);
app.use(viewHelpers);
// Routes & controllers
app.use("/session", sessionController);
app.use("/feed", ensureLoggedIn, feedController);
app.use("/post", postController);
app.use("/user", userController);
app.get("/", (req, res) => {
res.render("login");
});
app.listen(port, () => {
console.log(`now listening on ${port}`);
})