From 36b18d3b1d12551b58a60ee16b1afcd09be88f35 Mon Sep 17 00:00:00 2001 From: Morgan Ney Date: Thu, 15 Jul 2021 09:24:50 -0500 Subject: [PATCH] Switch to umo and proxy over https --- README.md | 4 +- lib/api/agencies.js | 6 +-- lib/api/predictions.js | 18 +++---- lib/api/routes.js | 6 +-- lib/api/vehicles.js | 10 ++-- lib/utils.js | 13 ++--- package-lock.json | 118 ++++++++++++++++++++--------------------- package.json | 5 +- 8 files changed, 87 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 6601999..40992b5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/api/agencies.js b/lib/api/agencies.js index a3f23b9..8db31da 100644 --- a/lib/api/agencies.js +++ b/lib/api/agencies.js @@ -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 = {}; @@ -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; @@ -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; diff --git a/lib/api/predictions.js b/lib/api/predictions.js index 3ff0fce..268d019 100644 --- a/lib/api/predictions.js +++ b/lib/api/predictions.js @@ -1,4 +1,4 @@ -var http = require('http'); +var https = require('https'); var zlib = require('zlib'); var qs = require('querystring'); var utils = require('../utils'); @@ -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; @@ -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; @@ -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) { @@ -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, @@ -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; }); diff --git a/lib/api/routes.js b/lib/api/routes.js index cd70fcb..7e89cca 100644 --- a/lib/api/routes.js +++ b/lib/api/routes.js @@ -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; @@ -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; @@ -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; diff --git a/lib/api/vehicles.js b/lib/api/vehicles.js index c7b3469..0ad1d85 100644 --- a/lib/api/vehicles.js +++ b/lib/api/vehicles.js @@ -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; @@ -77,8 +77,8 @@ 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, @@ -86,7 +86,7 @@ vehicles.list = function(req, res) { 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; @@ -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; diff --git a/lib/utils.js b/lib/utils.js index 24b0642..e1caf8b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 = {}; diff --git a/package-lock.json b/package-lock.json index 89c5e98..57c2946 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "restbus", - "version": "1.2.2", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,7 +9,7 @@ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", "requires": { - "mime-types": "~2.1.18", + "mime-types": "2.1.22", "negotiator": "0.6.1" } }, @@ -32,15 +32,15 @@ "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", "requires": { "bytes": "3.1.0", - "content-type": "~1.0.4", + "content-type": "1.0.4", "debug": "2.6.9", - "depd": "~1.1.2", + "depd": "1.1.2", "http-errors": "1.7.2", "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", + "on-finished": "2.3.0", "qs": "6.7.0", "raw-body": "2.4.0", - "type-is": "~1.6.17" + "type-is": "1.6.18" }, "dependencies": { "bytes": { @@ -73,7 +73,7 @@ "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.17.tgz", "integrity": "sha512-BGHeLCK1GV7j1bSmQQAi26X+GgWcTjLr/0tzSvMCl3LH1w1IJ4PFSPoV5316b30cneTziC+B1a+3OjoSUcQYmw==", "requires": { - "mime-db": ">= 1.40.0 < 2" + "mime-db": "1.40.0" }, "dependencies": { "mime-db": { @@ -88,13 +88,13 @@ "resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz", "integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==", "requires": { - "accepts": "~1.3.5", + "accepts": "1.3.5", "bytes": "3.0.0", - "compressible": "~2.0.16", + "compressible": "2.0.17", "debug": "2.6.9", - "on-headers": "~1.0.2", + "on-headers": "1.0.2", "safe-buffer": "5.1.2", - "vary": "~1.1.2" + "vary": "1.1.2" } }, "content-disposition": { @@ -153,8 +153,8 @@ "resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.5.0.tgz", "integrity": "sha1-6rpkyl1UKjEayUX1gt78M2Fl2fQ=", "requires": { - "accepts": "~1.3.3", - "escape-html": "~1.0.3" + "accepts": "1.3.5", + "escape-html": "1.0.3" } }, "escape-html": { @@ -172,36 +172,36 @@ "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", "requires": { - "accepts": "~1.3.7", + "accepts": "1.3.7", "array-flatten": "1.1.1", "body-parser": "1.19.0", "content-disposition": "0.5.3", - "content-type": "~1.0.4", + "content-type": "1.0.4", "cookie": "0.4.0", "cookie-signature": "1.0.6", "debug": "2.6.9", - "depd": "~1.1.2", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.1.2", + "depd": "1.1.2", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "finalhandler": "1.1.2", "fresh": "0.5.2", "merge-descriptors": "1.0.1", - "methods": "~1.1.2", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", + "methods": "1.1.2", + "on-finished": "2.3.0", + "parseurl": "1.3.3", "path-to-regexp": "0.1.7", - "proxy-addr": "~2.0.5", + "proxy-addr": "2.0.5", "qs": "6.7.0", - "range-parser": "~1.2.1", + "range-parser": "1.2.1", "safe-buffer": "5.1.2", "send": "0.17.1", "serve-static": "1.14.1", "setprototypeof": "1.1.1", - "statuses": "~1.5.0", - "type-is": "~1.6.18", + "statuses": "1.5.0", + "type-is": "1.6.18", "utils-merge": "1.0.1", - "vary": "~1.1.2" + "vary": "1.1.2" }, "dependencies": { "accepts": { @@ -209,7 +209,7 @@ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", "requires": { - "mime-types": "~2.1.24", + "mime-types": "2.1.24", "negotiator": "0.6.2" } }, @@ -252,12 +252,12 @@ "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", "requires": { "debug": "2.6.9", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "statuses": "~1.5.0", - "unpipe": "~1.0.0" + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "on-finished": "2.3.0", + "parseurl": "1.3.3", + "statuses": "1.5.0", + "unpipe": "1.0.0" }, "dependencies": { "debug": { @@ -290,10 +290,10 @@ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", "requires": { - "depd": "~1.1.2", + "depd": "1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.1", - "statuses": ">= 1.5.0 < 2", + "statuses": "1.5.0", "toidentifier": "1.0.0" } }, @@ -302,7 +302,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "requires": { - "safer-buffer": ">= 2.1.2 < 3" + "safer-buffer": "2.1.2" } }, "inherits": { @@ -345,7 +345,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.22.tgz", "integrity": "sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog==", "requires": { - "mime-db": "~1.38.0" + "mime-db": "1.38.0" } }, "morgan": { @@ -353,11 +353,11 @@ "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", "integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==", "requires": { - "basic-auth": "~2.0.0", + "basic-auth": "2.0.1", "debug": "2.6.9", - "depd": "~1.1.2", - "on-finished": "~2.3.0", - "on-headers": "~1.0.1" + "depd": "1.1.2", + "on-finished": "2.3.0", + "on-headers": "1.0.2" }, "dependencies": { "debug": { @@ -413,7 +413,7 @@ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz", "integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==", "requires": { - "forwarded": "~0.1.2", + "forwarded": "0.1.2", "ipaddr.js": "1.9.0" } }, @@ -466,18 +466,18 @@ "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", "requires": { "debug": "2.6.9", - "depd": "~1.1.2", - "destroy": "~1.0.4", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", + "depd": "1.1.2", + "destroy": "1.0.4", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", "fresh": "0.5.2", - "http-errors": "~1.7.2", + "http-errors": "1.7.2", "mime": "1.6.0", "ms": "2.1.1", - "on-finished": "~2.3.0", - "range-parser": "~1.2.1", - "statuses": "~1.5.0" + "on-finished": "2.3.0", + "range-parser": "1.2.1", + "statuses": "1.5.0" }, "dependencies": { "debug": { @@ -507,9 +507,9 @@ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", "requires": { - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "parseurl": "1.3.3", "send": "0.17.1" } }, @@ -534,7 +534,7 @@ "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", "requires": { "media-typer": "0.3.0", - "mime-types": "~2.1.24" + "mime-types": "2.1.24" }, "dependencies": { "mime-db": { @@ -572,8 +572,8 @@ "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", "requires": { - "sax": ">=0.6.0", - "xmlbuilder": "~9.0.1" + "sax": "1.2.4", + "xmlbuilder": "9.0.7" } }, "xmlbuilder": { diff --git a/package.json b/package.json index 0865a60..d429645 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "restbus", "description": "RESTful JSON API for the NextBus Inc. public XML feed.", - "version": "1.3.0", + "version": "2.0.0", "main": "index", "dependencies": { "compression": "1.7.4", @@ -19,6 +19,7 @@ }, "homepage": "http://restbus.info", "keywords": [ + "umo", "nextbus", "api", "rest", @@ -30,7 +31,7 @@ }, "author": { "name": "Morgan Ney ", - "url": "http://bizzybytes.com" + "url": "https://morgan.neys.info" }, "license": "MIT", "scripts": {