-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (54 loc) · 1.78 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
// Imports ------------------------------------------------
const express = require("express");
const app = express();
const path = require("path");
const passport = require("passport");
const multer = require("multer");
const bodyParser = require("body-parser");
const session = require("express-session");
const render = require("ejs");
const methodOverride = require("method-override");
const storiesRoute = require("./routes/stories-routes");
const adminRoute = require("./routes/admin-routes");
const authRoute = require("./routes/auth-routes");
const aboutUsRoute = require("./routes/about-us-routes");
const db = require("./models/models");
// ---------------------------------------------------------
// "Use" is for middleware ---------------------------------
const publicPath = path.join(__dirname, "public");
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/auth", authRoute);
app.use("/stories-routes", storiesRoute);
app.use("/admin", adminRoute);
app.use("/about-us", aboutUsRoute);
app.use(
express.static(publicPath, {
setHeaders: (res, path) => {
if (path.endsWith(".css")) {
res.setHeader("Content-Type", "text/css");
}
},
})
);
app.use(async (req, res, next) => {
req.db = db;
next();
});
app.use(express.urlencoded({ extended: false }));
app.use(methodOverride("_method"));
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "/views"));
// ------------------------------------------------------
// Get request for the entry point of app
// Home page
const PORT = 3000;
app.listen(3000, function (err) {
if (err) {
console.log(err);
}
console.log(`app is listening on port ${PORT}`);
});
app.get("/", (req, res) => {
res.render(path.join(__dirname, "index.ejs"));
});