-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.js
55 lines (48 loc) · 2.17 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require("express");
const app = express();
const port = process.env.PORT || 5000;
const available_cards = {
"/jokes-card": require("./src/cards/joke-card"),
"/programming-quotes-card": require("./src/cards/programming-quote"),
"/motivational-quotes-card": require("./src/cards/motivational-quote"),
"/word-of-the-day-card": require("./src/cards/word_of_the_day"),
"/challenge-of-the-week-card": require("./src/cards/challenge-of-the-week"),
"/team-work-quote-card": require("./src/cards/team-work-quote"),
"/breaking-bad-quote-card" : require("./src/cards/breaking-bad-quotes"),
"/bhagavad-geeta-card": require("./src/cards/bhagavad-geeta-quotes"),
"/programming-facts-card": require("./src/cards/programming-facts"),
"/spanish-quote-card": require("./src/cards/spanish-quote"),
"/top-tweets-card": require("./src/cards/top-tweets"),
"/github-facts-card": require("./src/cards/github-facts"),
"/security-tips-card": require("./src/cards/security-tips-cards"),
"/random-facts-card": require("./src/cards/random-facts"),
"/fun-fact-card": require("./src/cards/fun-fact-card"),
"/got-quotes-card": require("./src/cards/got-quotes"),
"/harry-potter-spell-card": require("./src/cards/harry-potter-spells"),
"/travel-destinations-card": require("./src/cards/travel_destinations"),
"/french-word-of-the-day-card": require("./src/cards/french_word_of_the_day"),
"/health-tip-card": require("./src/cards/health-tip-card"),
};
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use("/help", require("./src/help"));
// serve public directory on root
app.use("/", express.static("public"));
for (const key in available_cards) {
if (available_cards.hasOwnProperty(key)) {
app.use(key, available_cards[key]);
}
}
app.get("/random-card", (req, res) => {
let urls = Object.keys(available_cards);
let query = "";
if (req.originalUrl.indexOf("?") > -1) {
const queryParameters = req.originalUrl.split("?")[1];
query = `?${queryParameters}`;
}
const randomIndex = Math.floor(Math.random() * urls.length);
res.redirect(urls[randomIndex] + query);
});
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});