-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (37 loc) · 1.35 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
const express = require("express");
const session = require("express-session");
const exphbs = require("express-handlebars");
const passport = require("./config/passport");
const db = require("./models");
const htmlRoutes = require("./routes/htmlRoutes");
const apiUserRoutes = require("./routes/user-apiRoutes");
const apiStoriesRoutes = require("./routes/story-apiRoutes");
// Set up port to work with Heroku as well
var PORT = process.env.PORT || 5050;
const app = express();
// Configure express app server
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static("public"));
// Configure express to use sessions and passport middleware for authentication
app.use(
session({ secret: "keyboard cat", resave: true, saveUninitialized: true })
);
app.use(passport.initialize());
app.use(passport.session());
// Configure Handlebars.
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Configure routes
// app.use(apiUserRoutes);
// app.use(apiStoriesRoutes);
// app.use(htmlRoutes);
app.use("/api/stories", apiStoriesRoutes);
app.use("/api", apiUserRoutes);
app.use("/", htmlRoutes);
// Sync the database and log a message upon success
db.sequelize.sync({}).then(function () {
app.listen(PORT, () => {
console.log(`Server listening on: http://localhost:${PORT}`);
});
});