/
index.js
66 lines (52 loc) · 1.61 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
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express'),
app = express(),
firebase = require('firebase'),
r = require('request'),
bodyParser = require('body-parser'),
https = require('https');
app.use(bodyParser.json());
app.get('/',function(req,res){
res.send("Hello world");
});
var fb = new firebase('shining-fire-9321.firebaseio.com');
app.get('/stations',function(req,res){
fb.child('stations').on('value',function(snapshot){
res.format({
"application/json": function(){
res.send(snapshot.val());
}
});
});
});
app.get('/journey/:from/to/:to', function(req,res){
var username = "rttapi_birdyboy18";
var password = "9c085a1a190ac4008255927293122d0aef0529cf";
var auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
var url = "https://api.rtt.io/api/v1/json/search/" + req.params.from + "/to/" + req.params.to;
var authURL = "http://" + username + ":" + password + "@api.rtt.io/api/v1/json/search/" + req.params.from + "/to/" + req.params.to;
//console.log(auth);
var options = {
hostname: "api.rtt.io",
path: "/api/v1/json/search/" + req.params.from + "/to/" + req.params.to,
method: 'GET',
auth: {
username: username,
password: password
},
rejectUnauthorized: false,
requestCert: false,
agent: false
}
var req = https.request(options, function(res) {
console.log("statusCode" + res.statusCode);
console.log("headers: " + res.headers);
res.on('data', function(data){
console.log(data);
});
});
req.end();
req.on('error',function(err){
console.log(err);
});
});
app.listen(3000);