This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
133 lines (107 loc) · 3.7 KB
/
server.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const express = require("express");
const ip = require("ip");
const app = express();
const generic = require("./api/alirdb/generic");
const players = require("./api/alirdb/players");
const lists = require("./api/alirdb/list");
const users = require("./api/alirdb/users");
const vehicle = require("./api/alirdb/vehicle");
const wanted = require("./api/alirdb/wanted");
const gangs = require("./api/alirdb/gangs");
const steam = require("./api/steam/steam");
const donations = require("./api/donations/donations");
const auth = require("http-auth");
const morgan = require("morgan");
const cors = require("cors");
//const https = require("https");
const fs = require("fs");
const Feed = require("rss-to-json");
const CronJob = require("cron").CronJob;
/* ---------------------------------- */
const port = 8190;
const HOST = ip.address();
/* ---------------------------------- */
//const key = fs.readFileSync('/home/andreacw/webapi/key/server.key');
//const cert = fs.readFileSync( '/home/andreacw/webapi/key/server.crt' );
//const ca = fs.readFileSync( '/home/andreacw/webapi/key/ca.crt' );
/*const options = {
key: key,
cert: cert,
ca: ca
};*/
app.listen(port, HOST);
console.log(" ---- ALIR WebApi ---- ");
console.log(`In esecuzione su http://${HOST}:${port}`);
// TODO: HTTPS Request
const basic = auth.basic({
realm: "ALIRWebApi",
file: "./htpasswd/user.htpasswd"
}
);
//https.createServer(options, app).listen(8191);
const corsOptions = {
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204
};
app.use(morgan('dev'));
app.use(cors(corsOptions));
app.use(function(req, res, next) {
if ('/specific/path' === req.path) {
next();
} else {
(auth.connect(basic))(req, res, next);
}
});
/*basic.on('success', (result, req) => {
winston.info("User " + result.user + " authenticated");
});*/
basic.on('fail', (result, req) => {
console.warn("User " + result.user + " authentication failed");
});
basic.on('error', (error, req) => {
console.error("Authentication error: " + error.code + " - " + error.message);
});
const job = new CronJob('*/15 * * * *', function() {
const key = "01f5ac2969949545e480ece0ac98ba12";
const rss_discussion = "https://www.alir.eu/rss/1-rss-discussioni.xml/";
const rss_news = "https://www.alir.eu/rss/3-annunci.xml/";
const discussioniJson = "/home/andreacw/webapi/discussioni.json";
const annunciJson = "/home/andreacw/webapi/annunci.json";
Feed.load( rss_discussion + "/?member_id=3634&key=" + key, function (err, rss) {
let json = JSON.stringify(rss);
if (err){
console.log(err);
} else {
fs.writeFile(discussioniJson, json, 'utf8',function(err) {});
}
});
Feed.load( rss_news + "/?member_id=3634&key=" + key, function (err, rss) {
let json = JSON.stringify(rss);
if (err){
console.log(err);
} else {
fs.writeFile(annunciJson, json, 'utf8',function(err) {});
}
});
console.info("Updated RSS Feed completed!")
}, function () {
console.error("Error: CRON disabled.")
},
true,
"America/Los_Angeles"
);
job.start();
// Richieste ALIRDB
generic(app);
players(app);
gangs(app);
vehicle(app);
wanted(app);
lists(app);
users(app);
// Richieste donazioni
donations(app);
// Richieste di Steam e di Arma3Servers
steam(app);