Skip to content

Commit

Permalink
Merge pull request #12 from morganney/develop
Browse files Browse the repository at this point in the history
Switch to umo and proxy over https
  • Loading branch information
morganney committed Jul 15, 2021
2 parents 0d6ddce + 36b18d3 commit 9b8d160
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 93 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Converts the [NextBus][1] [Public XML Feed][2], which is used to build real-time
All documentation is hosted at [restbus.info][0].

[0]: http://restbus.info
[1]: http://www.nextbus.com
[2]: http://www.nextbus.com/xmlFeedDocs/NextBusXMLFeed.pdf
[1]: https://retro.umoiq.com/
[2]: https://retro.umoiq.com/xmlFeedDocs/NextBusXMLFeed.pdf
6 changes: 3 additions & 3 deletions lib/api/agencies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http');
var https = require('https');
var utils = require('../utils');
var NBXML_FEED = utils.c.NEXTBUS_XMLFEED;
var agencies = {};
Expand Down Expand Up @@ -58,7 +58,7 @@ function getLinks(hrefs, agency, req) {
}

agencies.list = function(req, res) {
http.get(utils.getOptionsWithPath(NBXML_FEED + '?command=agencyList'), function(nbres) {
https.get(utils.getOptionsWithPath(NBXML_FEED + '?command=agencyList'), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var json = [],
uri;
Expand All @@ -85,7 +85,7 @@ agencies.list = function(req, res) {
agencies.get = function(req, res) {
var agency_id = req.params.agency;

http.get(utils.getOptionsWithPath(NBXML_FEED + '?command=agencyList'), function(nbres) {
https.get(utils.getOptionsWithPath(NBXML_FEED + '?command=agencyList'), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var json = false,
uri, ruri, vuri, auri;
Expand Down
18 changes: 9 additions & 9 deletions lib/api/predictions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http');
var https = require('https');
var zlib = require('zlib');
var qs = require('querystring');
var utils = require('../utils');
Expand All @@ -14,7 +14,7 @@ predictions.get = function(req, res) {
onsplit = params.onsplit || 'routes',
path = params.path || [NBXML_FEED, '?command=predictions&a=', a, '&r=', r, '&s=', s].join('');

http.get(utils.getOptionsWithPath(path), function(nbres) {
https.get(utils.getOptionsWithPath(path), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var json = [], nberr, url, uri;

Expand Down Expand Up @@ -149,8 +149,8 @@ predictions.get = function(req, res) {
*
* @uri /agencies/:agency/stops/:code/predictions
*
* @param {Object:req} The node native http.ClientRequest object.
* @param {Object:res} The node native http.ServerResponse object.
* @param {Object:req} The node native https.ClientRequest object.
* @param {Object:res} The node native https.ServerResponse object.
*/
predictions.list = function(req, res) {
var p = req.params;
Expand All @@ -164,8 +164,8 @@ predictions.list = function(req, res) {
* Tuples <====> F:5650 (route-id:stop-id)
* @uri /agencies/:agency/tuples/:tuples/predictions e.g. /agencies/sf-muni/tuples/F:5650,N:6997/predictions
*
* @param {Object:req} The node native http.ClientRequest object.
* @param {Object:res} The node native http.ServerResponse object.
* @param {Object:req} The node native https.ClientRequest object.
* @param {Object:res} The node native https.ServerResponse object.
*/

predictions.tuples = function(req, res) {
Expand All @@ -190,8 +190,8 @@ predictions.tuples = function(req, res) {
* UNSTABLE: The data from NextBus behind this request can be removed at any moment and
* without notice. Use this particular method at your own risk.
*
* @param {Object:req} The node native http.ClientRequest object.
* @param {Object:res} The node native http.ServerResponse object.
* @param {Object:req} The node native https.ClientRequest object.
* @param {Object:res} The node native https.ServerResponse object.
*/
predictions.location = function(req, res) {
var p = req.params,
Expand Down Expand Up @@ -220,7 +220,7 @@ predictions.location = function(req, res) {
'content-length': postdata.length
}
};
postreq = http.request(options, function(nbres) {
postreq = https.request(options, function(nbres) {
var nbjson = '';

nbres.on('data', function(d) { if(d) nbjson += d; });
Expand Down
6 changes: 3 additions & 3 deletions lib/api/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http');
var https = require('https');
var utils = require('../utils');
var C = utils.c;
var NBXML_FEED = C.NEXTBUS_XMLFEED;
Expand Down Expand Up @@ -55,7 +55,7 @@ routes.list = function(req, res) {
var path = [NBXML_FEED, '?command=routeList&a=', req.params.agency].join(''),
params = req.params;

http.get(utils.getOptionsWithPath(path), function(nbres) {
https.get(utils.getOptionsWithPath(path), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var json = [],
nberr, rte, uri;
Expand Down Expand Up @@ -127,7 +127,7 @@ routes.get = function(req, res) {
var p = req.params,
path = [NBXML_FEED, '?command=routeConfig&a=', p.agency, '&r=', p.route].join('');

http.get(utils.getOptionsWithPath(path), function(nbres) {
https.get(utils.getOptionsWithPath(path), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var json = {},
route, $, nberr, uri, vuri, ruri;
Expand Down
10 changes: 5 additions & 5 deletions lib/api/vehicles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var http = require('http');
var https = require('https');
var utils = require('../utils');
var C = utils.c;
var NBXML_FEED = C.NEXTBUS_XMLFEED;
Expand Down Expand Up @@ -77,16 +77,16 @@ function getLinks(hrefs, v, req) {
* parameter in the request to NextBus, but leave it without a value, then all agency vehicles are
* returned as desired. However, including it allows us to reuse this method for vehicles.routelist.
*
* @param {Object:req} The node native http.ClientRequest object.
* @param {Object:res} The node native http.ServerResponse object.
* @param {Object:req} The node native https.ClientRequest object.
* @param {Object:res} The node native https.ServerResponse object.
*/
vehicles.list = function(req, res) {
var p = req.params,
a = p.agency,
r = p.route ? p.route : '',
path = [NBXML_FEED, '?command=vehicleLocations&a=', a, '&r=', r, '&t=0'].join('');

http.get(utils.getOptionsWithPath(path), function(nbres) {
https.get(utils.getOptionsWithPath(path), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var json = [], nberr, vehicles, uri, ruri;

Expand Down Expand Up @@ -128,7 +128,7 @@ vehicles.get = function(req, res) {
v = p.vehicle,
path = [NBXML_FEED, '?command=vehicleLocation&a=', a, '&v=', v].join('');

http.get(utils.getOptionsWithPath(path), function(nbres) {
https.get(utils.getOptionsWithPath(path), function(nbres) {
utils.getJsFromXml(nbres, function(err, js) {
var nberr, uri, auri, ruri;

Expand Down
13 changes: 3 additions & 10 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
var zlib = require('zlib');
var js4xml = require('xml2js').parseString;
// @see https://retro.umoiq.com/xmlFeedDocs/NextBusXMLFeed.pdf
var options = {
hostname: 'webservices.nextbus.com',
host: 'retro.umoiq.com',
hostname: 'retro.umoiq.com',
headers: {'accept-encoding':'gzip,deflate'}
// Make http request to NextBus use 'Connection: close' instead of 'Connection: keep-alive'
// Might help with avoiding the weird node.js error when restarting server (and/or changing NODE_ENV):
//
// Error: read ECONNRESET
// at errnoException (net.js:901:11)
// at TCP.onread (net.js:556:19)
//
// @see http://nodejs.org/api/http.html#http_http_request_options_callback
// agent: false
};
var utils = {};

Expand Down
Loading

0 comments on commit 9b8d160

Please sign in to comment.