-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathskyProxy.js
43 lines (38 loc) · 911 Bytes
/
skyProxy.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
var common = require('./common');
module.exports = {
skyProxy : function(req,res) {
var s = '';
for (var q in req.query) {
if (Array.isArray(req.query[q])) {
for (var a=0;a<req.query[q].length;a++) {
s += (s ? '&' : '?') + q + '=' + encodeURIComponent(req.query[q][a]);
}
}
else {
if (q != 'api_key') {
s += (s ? '&' : '?') + q + '=' + encodeURIComponent(req.query[q]);
}
}
}
s = req.path.replace('/sky','') + s;
var options = {
host: 'www.sky.com',
port: 80,
path: s,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
};
common.getJSON(options,function(stateCode,obj) {
res.setHeader('Access-Control-Allow-Origin','*');
if (stateCode == 200) {
res.send(JSON.stringify(obj,null,2));
}
else {
res.send('Request failed with statusCode; '+stateCode);
}
});
}
};