forked from dr4fters/dr4ft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (34 loc) · 1.17 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
const http = require("http");
const schedule = require("node-schedule");
const eio = require("engine.io");
const express = require("express");
const helmet = require("helmet");
const fileUpload = require("express-fileupload");
const cors = require("cors");
const bodyParser = require("body-parser");
const logger = require("./backend/logger");
const router = require("./backend/router");
const apiRouter = require("./backend/api/");
const allSets = require("./scripts/download_allsets");
const {app: config, version} = require("./config");
const app = express();
//Middlewares
app.use(helmet());
app.use(bodyParser.json()); // for parsing application/json
app.use(cors());
app.use(fileUpload());
//routing
app.use(express.static("built"));
app.use("/api", apiRouter);
// Download Allsets.json if there's a new one and make the card DB
allSets.download();
// Schedule check of a new AllSets.json every hour
schedule.scheduleJob("0 * * * *", () => {
allSets.download();
});
// Create server
const server = http.createServer(app);
const io = eio(server);
io.on("connection", router);
server.listen(config.PORT);
logger.info(`Started up on port ${config.PORT} with version ${version}`);