-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.js
46 lines (41 loc) · 1.17 KB
/
api.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
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const config = require("config");
const cron = require("node-cron");
const users = require("./routes/users");
const championships = require("./routes/championships");
const bets = require("./routes/bets");
const slot = require("./routes/slot");
const ranking = require("./routes/ranking");
const updateMatchResults = require("./middlewares/updateMatchResults");
require("./prod")(app);
[
"jwtPrivateKey",
"the_odds_api_key",
"db_password",
"redis_host",
"redis_port",
"redis_password",
"db_username",
].forEach((i) => {
if (!config.get(i)) {
console.error(`FATAL ERROR: ${i} NOT DEFINED!`);
process.exit(1);
}
});
updateMatchResults();
cron.schedule("*/5 * * * *", () => {
updateMatchResults();
});
app.use(cors({ origin: "*" }));
app.use(bodyParser.json());
app.use("/users", users);
app.use("/championships", championships);
app.use("/bets", bets);
app.use("/slot", slot);
app.use("/ranking", ranking);
module.exports = app.listen(process.env.PORT || 3001, () => {
console.log(`Example app listening at http://localhost:3001`);
});