forked from Andrew0502/project-2-group-15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (43 loc) · 1.3 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
const express = require("express");
const exphbs = require("express-handlebars");
const handlebars = require("handlebars");
const {
allowInsecurePrototypeAccess,
} = require("@handlebars/allow-prototype-access");
const app = express();
const db = require("./models");
const apiRoutes = require("./routes/api-routes.js");
const htmlRoutes = require("./routes/html-routes.js");
const path = require ("path");
const PORT = process.env.PORT || 8080;
//api key hiding
//middleware
//used to interpert spaces in urls
app.use(express.static(path.join(__dirname,"/public")));
app.use(express.urlencoded({ extended: true }));
//changing data into json
app.use(express.json());
//view engine using handlebar to display our html pages
app.engine("handlebars", exphbs({ defaultLayout: "main",
handlebars: allowInsecurePrototypeAccess(handlebars), }));
app.set("view engine", "handlebars");
//calling our api html routes
apiRoutes(app);
htmlRoutes(app);
// //
// // views routes
app.get("/", (req, res) => {
res.render("index");
});
// api routes
// app.get("/api/config", (req, res) => {
// res.json({
// success: true,
// });
// });
//running out server
db.sequelize.sync().then(function (){
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
});