-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (28 loc) · 1.03 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
const express = require("express");
const path = require("path");
const cookieParser = require('cookie-parser');
const { connectToMongoDB } = require("./connections");
const userRoute = require("./routes/user");
const blogRoute = require("./routes/blog");
const commentRoute = require("./routes/comment");
const rootRoute = require("./routes/root");
const { checkForAuthenticationCookie } = require("./middlewares/auth");
const app = express();
const PORT = 8000;
const dburl = "mongodb://127.0.0.1:27017/adblogs";
connectToMongoDB(dburl).then(() => {
console.log("MongoDb Connected...")
});
app.set("view engine", "ejs");
app.set("views", path.resolve("./views"));
app.use(express.urlencoded({ extended:true }));
app.use(cookieParser());
app.use(checkForAuthenticationCookie("token"));
app.use(express.static(path.resolve('./public')));
app.use("/user", userRoute);
app.use("/blog", blogRoute);
app.use("/comment", commentRoute);
app.use("/", rootRoute);
app.listen(PORT, () => {
console.log(`Server started at ${PORT} ...`);
});