-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (64 loc) · 2.1 KB
/
index.js
File metadata and controls
76 lines (64 loc) · 2.1 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require("dotenv").config();
const express = require("express");
const app = express();
const firebase = require("firebase/app");
const firebaseConfig = require("./firebaseConfig");
// if (!firebase.apps.length) {
// firebase.initializeApp(firebaseConfig);
// firebase.initializeApp({});
// }else {
// }
// firebase.app(); // if already initialized, use that one
require("firebase/firestore");
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static("static"));
const {
codechefHandler,
codeforcesHandler,
hackerearthHandler,
} = require("./functions/events");
const {
hackerearthRating,
codeforcesRating,
codechefRating,
} = require("./functions/rating");
const {
webhookPostHandler,
webhookGetHandler,
} = require("./functions/messenger");
const { sendNotifications } = require("./functions/dailyNotif");
// const { reset } = require("nodemon");
const { config } = require("dotenv");
app.get("/", (req, res) => {
console.log("GET /");
res.json({ status: "active" });
});
app.get("/events/codeforces", async (req, res) => {
res.send(await codeforcesHandler());
});
app.get("/events/hackerearth", async (req, res) => {
res.send(await hackerearthHandler());
});
app.get("/events/codechef", async (req, res) => {
res.send(await codechefHandler());
});
app.post("/mg-api/webhook", webhookPostHandler);
app.get("/mg-api/webhook", webhookGetHandler);
app.get("/dailynotification", sendNotifications);
app.post("/dailynotification", sendNotifications);
app.get("/rating/hackerearth/:username", async (req, res) => {
res.send(await hackerearthRating('hackerearth', req.params.username));
});
app.get("/rating/codeforces/:username", async (req, res) => {
res.send(await codeforcesRating('codeforces', req.params.username));
});
app.get("/rating/codechef/:username", async (req, res) => {
res.send(await codechefRating('codechef', req.params.username));
});
// --- LISTEN TO REQUESTS ---
const listener = app.listen(process.env.PORT || 5000, () => {
console.log(">> Listening on PORT " + listener.address().port);
});
listener;