-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (32 loc) · 1.16 KB
/
app.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
require("dotenv").config();
const path = require("path");
const express = require("express");
const mongoose = require("mongoose");
const cookiePaser = require("cookie-parser");
const Blog = require("./models/blog");
const userRoute = require("./routes/user");
const blogRoute = require("./routes/blog");
const {
checkForAuthenticationCookie,
} = require("./middlewares/authentication");
const app = express();
const PORT = process.env.PORT || 8000;
mongoose
.connect("mongodb+srv://wanisanika2004:[email protected]/goFoodmern?retryWrites=true&w=majority&appName=Cluster")
.then((e) => console.log("MongoDB Connected"));
app.set("view engine", "ejs");
app.set("views", path.resolve("./views"));
app.use(express.urlencoded({ extended: false }));
app.use(cookiePaser());
app.use(checkForAuthenticationCookie("token"));
app.use(express.static(path.resolve("./public")));
app.get("/", async (req, res) => {
const allBlogs = await Blog.find({});
res.render("home", {
user: req.user,
blogs: allBlogs,
});
});
app.use("/user", userRoute);
app.use("/blog", blogRoute);
app.listen(PORT, () => console.log(`Server Started at PORT:${PORT}`));