-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (40 loc) · 1.25 KB
/
index.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
const express = require("express");
const hbs = require("hbs");
const dotenv = require("dotenv");
const routes = require("./routes/routes.js");
const mongoose = require("mongoose");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);
const db = require("./models/db.js");
const app = express();
app.set("view engine", "hbs");
hbs.registerPartials(__dirname + "/views/partials");
hbs.registerHelper("inSession", (loggedUser, cAuthor, options) => {
console.log(cAuthor);
console.log(loggedUser);
if (cAuthor == loggedUser) return options.fn(this);
});
dotenv.config();
const HOSTNAME = process.env.HOSTNAME;
const PORT = process.env.PORT || 3000;
app.use(express.urlencoded({ extended: true }));
app.use(express.static("public"));
app.use(
session({
secret: "ccapdev-session",
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
})
);
app.use("/", routes);
app.use((req, res) => {
res.render("error");
});
db.connect();
hbs.registerHelper("ifEquals", function (arg1, arg2, options) {
return arg1 == arg2 ? options.fn(this) : options.inverse(this);
});
app.listen(PORT, () => {
console.log("server running at: " + "http://localhost:" + PORT + "/");
});