-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (49 loc) · 1.85 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import "dotenv/config";
import express from "express";
import projectsRouter from "./routes/projects.js";
import skillsRouter from "./routes/skills.js";
import contactRouter from "./routes/contact.js";
import socialsRouter from "./routes/socials.js";
import Database from "./utils/database.js";
import InfoTool from "./utils/infoTool.js";
import Utils from "./utils/utils.js";
import ProblemsSolvedTracker from "./utils/problemsSolvedTracker.js";
const app = express();
const port = process.env.PORT || 8000;
app.set("view engine", "ejs");
app.use("/public", express.static("public"));
app.use(express.urlencoded());
app.get("/", (req, res) => {
res.render("index");
Database.insertPageVisit(InfoTool.getPageId("home"));
});
app.get("/about", (req, res) => {
res.render("about");
Database.insertPageVisit(InfoTool.getPageId("about"));
});
app.get("/problems-solved", async (req, res) => {
const Tracker = ProblemsSolvedTracker;
const codewars = await Tracker.getCodewarsStats();
const codeforces = await Tracker.getCodeforcesStats();
const codechef = await Tracker.getCodechefStats();
res.render("problems-solved", {
data: {
totalSolved: Utils.formatProblemsSolved(codewars + codeforces + codechef),
codewarsStats: Utils.formatProblemsSolved(codewars, true),
codeforcesStats: Utils.formatProblemsSolved(codeforces),
codechefStats: Utils.formatProblemsSolved(codechef),
},
});
Database.insertPageVisit(InfoTool.getPageId("problemsSolved"));
});
app.get("/deception", (req, res) => {
Database.insertPageVisit(InfoTool.getPageId("deception"));
res.redirect("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
});
app.use("/skills", skillsRouter);
app.use("/projects", projectsRouter);
app.use("/contact", contactRouter);
app.use("/socials", socialsRouter);
app.listen(port, () => {
console.log("Server is now running!");
});