-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
72 lines (59 loc) · 1.68 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
67
68
69
70
71
72
const express = require("express");
const exphbs = require("express-handlebars");
const bodyParser = require("body-parser");
require("dotenv").config();
const passport = require("passport");
const flash = require("connect-flash");
const cookieParser = require("cookie-parser");
const session = require("express-session");
const app = express();
const PORT = process.env.PORT || 3000;
const db = require("./models");
require("./config/passport")(passport);
app.use(session({
key: 'user_sid',
secret: process.env.MYSECRET,
resave: false,
saveUninitialized: false,
cookie: {
expires: 600000
}
}));
// Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// app.use(express.urlencoded({ extended: false }));
// app.use(express.json());
app.use(express.static("public"));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
// Handlebars
app.engine(
"handlebars",
exphbs({
defaultLayout: "main"
})
);
app.set("view engine", "handlebars");
// Routes
require("./routes/api-routes")(app, passport);
require("./routes/account-route")(app, passport);
require("./routes/html-routes")(app, passport);
const syncOptions = { force: false };
// If running a test, set syncOptions.force to true
// clearing the `testdb`
if (process.env.NODE_ENV === "test") {
syncOptions.force = true;
}
// Starting the server, syncing our models ------------------------------------/
db.sequelize.sync(syncOptions).then(function() {
app.listen(PORT, function() {
console.log(
"==> 🌎 Listening on port %s. Visit http://localhost:%s/ in your browser.",
PORT,
PORT
);
});
});
module.exports = app;