-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (46 loc) · 1.51 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
// ==========
// INIT
// ==========
var CronJob = require("cron").CronJob
var express = require("express")
var bodyParser = require('body-parser')
var dataHandler = require("./api/dataHandler")
var graphDataHandler = require("./api/graphDataHandler")
var app = express()
app.use(bodyParser.urlencoded({extended: true}))
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Content-Type");
next()
})
// ==========
// DAEMON
// ==========
console.log("Start factions daemon...")
new CronJob("0 */15 * * * *", function () {
console.log("Factions data are updating...")
dataHandler.generate()
}, function () {
console.log("Factions data are updated!")
}, true, "Europe/Paris")
console.log("Start factions graph daemon...")
new CronJob("0 0 0 * * 0", graphDataHandler.generate, function () {
console.log("Factions graph data are updated!")
}, true, "Europe/Paris")
// ==========
// GET DATA
// ==========
app.get('/data', dataHandler.display)
app.get('/data/refresh', function (req, res) {
res.send('done.')
console.log("Factions data are updating...")
dataHandler.generate()
})
app.get('/data/:factionId', dataHandler.displayFaction)
app.get('/data/:factionId/graph', graphDataHandler.displayFaction)
app.get('/data/search/user/:username', dataHandler.searchUser)
// ==========
// HANDLE WEB
// ==========
console.log("Start web api...")
app.listen(process.env.PORT || 8080);