-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
58 lines (41 loc) · 1.64 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
/*var port = process.argv.length < 3 ? 8080 : process.argv[2];
var connect = require('connect');
connect.createServer(
connect.static(__dirname)
).listen(port);
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Server running at http://127.0.0.1:" + port + "/\nExit with (x).", function(answer) {
if (answer === "x") {
console.log("Server stopped!");
rl.close();
process.exit();
}
});*/
var express = require('express');
var http = require('http');
var app = express();
var path = require('path');
var httpsync = require('httpsync');
app.set('port', process.env.PORT || 8080)
app.use(express.static(path.join(__dirname, 'public')));
app.use('/css', express.static(path.join(__dirname, '/css')));
app.use('/images', express.static(path.join(__dirname, '/images')));
app.use('/bower_components', express.static(path.join(__dirname, '/bower_components')));
app.use('/elements', express.static(path.join(__dirname, '/elements')));
app.get('/', function(req,res) {
res.sendfile('index.html');
});
app.get('/api/stats/:game/:nickname', function(req,res) {
var request = httpsync.get({ url : "http://www.easports.com/services/statscentral/getdata?platformTag=hockey-" + req.params.game +"-PS3&mode=versus&handle=" + req.params.nickname});
var response = request.end();
res.type('application/json');
res.send(response.data.toString());
});
//http://www.easports.com/services/statscentral/getdata?platformTag=hockey-nhl-14-PS3&mode=solo&handle=mr_nuno
var server = app.listen(8080, function() {
console.log('Listening on port %d', server.address().port);
});