-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
50 lines (41 loc) · 1.59 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
require('dotenv').config();
const express = require("express");
const session = require("express-session");
const exphbs = require("express-handlebars");
const exphbsSections = require("express-handlebars-sections");
// Requiring passport as we've configured it
const passport = require("./config/passport");
// Sets up the Express App
// =============================================================
const app = express();
const PORT = process.env.PORT || 8080;
// Requiring our models for syncing
const db = require("./models");
// Sets up the Express app to handle data parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// set handlebars
const hbs = exphbs.create({ defaultLayout: "main" });
exphbsSections(hbs);
app.engine("handlebars", hbs.engine);
app.set("view engine", "handlebars");
// Static directory
app.use(express.static("public"));
// 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());
// Routes
// =============================================================
const customerRoutes = require("./routes/html-routes.js");
const authRoutes = require("./routes/customer-routes");
app.use(customerRoutes, authRoutes);
// use first one to reset database during testing, otherwise use second line
// db.sequelize.sync({ force: true }).then(function () {
db.sequelize.sync().then(function () {
app.listen(PORT, function () {
console.log("App listening on PORT " + PORT);
})
}).catch((err) => { throw err });