-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (51 loc) · 1.16 KB
/
Copy pathindex.js
File metadata and controls
59 lines (51 loc) · 1.16 KB
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
var express = require('express');
var fs = require('fs');
var path = require('path');
var app = express();
var API = require('./API');
const appDir = path.dirname(require.main.filename) + '/';
const serverAddr = "localhost";
app.all("*", (req, resp, next) => {
console.log(req.method + ' ' + req.hostname + ' ' + req.path);
var reqData = "";
req.on('data', function(chunk){ reqData += chunk})
req.on('end', function(){
console.log(reqData);
});
resp.set({
'http_x_lid_hash': 'LET_IT_DIE_OFFLINE'
});
next();
});
//routes
app.use('/ap.conf', (req, resp) => {
resp.send({
"ver":0,
"envs":[
{
"name":"prds",
"urls":[
{
"type":"",
"ver":-1,
"url":serverAddr,
"region":""
}
]
}
]
});
});
app.use('/api/getparams.php', (req, resp) => {
resp.send(fs.readFileSync(appDir + 'Data/Params/' + 'apiparams.json'));
});
app.use('/api/getlocdat.php', (req, resp) => {
resp.send(fs.readFileSync(appDir + 'Data/Locdat/' + 'locdat.json'));
});
//dynamically register endpoints
for(let endpoint of Object.keys(API)) {
app.use('/api/' + endpoint + '.php', API[endpoint]);
}
app.listen(1337, () => {
console.log('listening on port 1337');
});