-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
62 lines (39 loc) · 1.36 KB
/
server.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
49
50
51
52
53
54
55
56
57
58
59
60
61
import express from "express";
import * as path from "path";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import {config} from "./config/config.js";
import { connectToMongoDB } from "./db/db.js";
import {cache} from "./config/redis.js";
// import { redirectShortUrlCache } from "./middleware/redirectShortUrlCache.middleware.js";
import authMiddleware from "./middleware/authentication.middleware.js";
import {limiter} from "./middleware/rateLimiter.js";
import homeRoute from "./routes/home.route.js";
import qrRoute from "./routes/qrCode.route.js";
import redirectRoute from "./routes/redirectShortUrl.route.js";
import urlRoute from "./routes/url.route.js";
import userRoute from "./routes/user.route.js";
const __dirname = path.resolve();
const app = express()
const PORT= config.port;
app.use(express.json());
app.use(limiter);
app.use(bodyParser.json())
.use(bodyParser.urlencoded({
extended: true
}));
app.set("view engine", "ejs")
app.use(express.static("public"))
app.set('views', path.join(__dirname, '/views'))
app.use(cookieParser());
//routes
app.use("/", homeRoute);
app.use("/", qrRoute)
app.use("/", userRoute);
app.use("/", authMiddleware, urlRoute);
app.use("/", redirectRoute)
cache.connect()
connectToMongoDB()
app.listen(PORT, () => {
console.log(`Server is listening at PORT ${PORT}`)
})