-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (56 loc) · 2.19 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
58
59
60
61
62
63
64
65
66
// Dependencies
// =============================================================
var express = require("express");
var bodyParser = require("body-parser");
var session = require("express-session");
var moment = require("moment");
require("dotenv").config();
// Requiring passport as we've configured it
var passport = require("./config/passport");
// Express App & Parser Setup
// =============================================================
var app = express();
var PORT = process.env.PORT || 8080;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// We need to use sessions to keep track of our user's login status
app.use(session({
secret: "keyboard cat",
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
// Setup Handlebars View Engine
// =============================================================
var exphbs = require("express-handlebars");
app.set("view engine", "handlebars");
app.engine("handlebars", exphbs({
"defaultLayout": "main",
// handlebars 'helpers' functions not used yet but may come in handy
// later, addOne is a sample handlebar helper function, not used yet
"helpers": {
// not used yet
"addOne": (value) => parseInt(value, 10) + 1,
// formates timestamp date into DD, MM NN, YYYY HH:MM format
// example Monday, May 21, 2018 5:41 PM
"fmtDate": (date) => moment(date).format("LLLL")
}
}));
// Database & Static Directory
// =============================================================
var db = require("./models");
app.use(express.static("public"));
// Routes
// =============================================================
require("./routes/html-routes.js")(app);
require("./routes/topics-api-routes.js")(app);
require("./routes/users-api-routes.js")(app);
require("./routes/choices-api-routes.js")(app);
// Syncing DB & Start Express
// =============================================================
db.sequelize.sync({ force: false }).then(function() {
app.listen(PORT, function() {
console.log("==> 🌎 App listening on PORT %s, http://localhost:%s ", PORT, PORT);
});
});