-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 993 Bytes
/
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
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const { connectDB } = require("./connection");
// const URL = require("./Model/url");
const userRouter = require("./Routes/userRouter");
const urlRouter = require("./Routes/url");
const staticRouter = require("./Routes/staticRouter");
const { restrictToLoggedInUserOnly,checkAuth } = require("./Middleware/auth");
const PORT = 8000;
const app = express();
//MongoDB Connection
connectDB("mongodb://127.0.0.1:27017/URL-Shortner").then(() =>
console.log("MongoDb Connected!")
);
app.set("view engine", "ejs");
app.set("views", path.resolve("./Views"));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cookieParser());
//Routes
app.use("/url", restrictToLoggedInUserOnly, urlRouter);
app.use("/user", userRouter);
//View Routes
app.use("/", checkAuth, staticRouter);
app.listen(PORT, () => console.log(`Server Started at PORT ${PORT}`));