-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (20 loc) · 822 Bytes
/
index.js
File metadata and controls
26 lines (20 loc) · 822 Bytes
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
import express from "express";
import path from "path";
import cookieParser from "cookie-parser";
import { connectMongoDB } from "./connect.js";
import { urlRouter } from "./routes/url.js";
import { staticRouter } from "./routes/staticRouter.js";
import { userRouter } from "./routes/userRoute.js";
import { restrictToLoggedInUserOnly, authGaurd } from "./middlewares/auth.js";
const app = express();
const PORT = 8001;
await connectMongoDB("mongodb://127.0.0.1:27017/short-url");
app.set("view engine", "ejs");
app.set("views", path.resolve("./views"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use("/", staticRouter);
app.use("/api", userRouter);
app.use("/api/url", urlRouter);
app.listen(PORT, () => console.log(`Server started at port: ${PORT}`));