-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
37 lines (30 loc) · 1.13 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
const express = require("express");
const exphbs = require("express-handlebars");
// var session = require("express-session");
// var passport = require("./config/passport");
// const path = require("path");
require("dotenv").config();
// Requiring our models for syncing
const htmlRouter = require("./routes/html-routes.js");
const authorRouter = require("./routes/author-api-routes.js");
const apiRouter = require("./routes/post-api-routes.js");
// Sets up the Express App
const app = express();
const PORT = process.env.PORT || 8080;
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Sets up the Express app to handle data parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Static directory
const db = require("./models");
app.use(express.static("views"));
app.use(express.static(__dirname + "/public"));
// Invoke routes
htmlRouter(app);
authorRouter(app);
apiRouter(app);
// Syncing our sequelize models and then starting our Express app
db.sequelize.sync({ force: false }).then(() => {
app.listen(PORT, () => console.log(`Listening on PORT ${PORT}`));
});