Browse Source

Merge pull request #929 from pelias/remove_express-http-proxy

deleted legacy routes and legacyURL code. Closes #868
pull/932/head
Lily He 8 years ago committed by GitHub
parent
commit
299cc98917
  1. 2
      README.md
  2. 3
      app.js
  3. 1
      package.json
  4. 34
      routes/legacy.js
  5. 2
      schema.js
  6. 24
      test/unit/schema.js

2
README.md

@ -42,7 +42,6 @@ The API recognizes the following properties under the top-level `api` key in you
|`host`|*yes*||specifies the url under which the http service is to run| |`host`|*yes*||specifies the url under which the http service is to run|
|`textAnalyzer`|*no*|*addressit*|can be either `libpostal` or `addressit` however will soon be **deprecated** and only `libpostal` will be supported going forward| |`textAnalyzer`|*no*|*addressit*|can be either `libpostal` or `addressit` however will soon be **deprecated** and only `libpostal` will be supported going forward|
|`indexName`|*no*|*pelias*|name of the Elasticsearch index to be used when building queries| |`indexName`|*no*|*pelias*|name of the Elasticsearch index to be used when building queries|
|`legacyUrl`|*no*||the url to redirect to in case the user does not specify a version such as `v1`
|`relativeScores`|*no*|true|if set to true, confidence scores will be normalized, realistically at this point setting this to false is not tested or desirable |`relativeScores`|*no*|true|if set to true, confidence scores will be normalized, realistically at this point setting this to false is not tested or desirable
|`accessLog`|*no*||name of the format to use for access logs; may be any one of the [predefined values](https://github.com/expressjs/morgan#predefined-formats) in the `morgan` package. Defaults to `"common"`; if set to `false`, or an otherwise falsy value, disables access-logging entirely.| |`accessLog`|*no*||name of the format to use for access logs; may be any one of the [predefined values](https://github.com/expressjs/morgan#predefined-formats) in the `morgan` package. Defaults to `"common"`; if set to `false`, or an otherwise falsy value, disables access-logging entirely.|
|`services`|*no*||service definitions for [point-in-polygon](https://github.com/pelias/pip-service) and [placholder](https://github.com/pelias/placeholder) services. If missing (which is not recommended), the point-in-polygon and placeholder services will not be called.| |`services`|*no*||service definitions for [point-in-polygon](https://github.com/pelias/pip-service) and [placholder](https://github.com/pelias/placeholder) services. If missing (which is not recommended), the point-in-polygon and placeholder services will not be called.|
@ -65,7 +64,6 @@ Example configuration file would look something like this:
"api": { "api": {
"host": "localhost:3100/v1/", "host": "localhost:3100/v1/",
"indexName": "foobar", "indexName": "foobar",
"legacyUrl": "pelias.mapzen.com",
"relativeScores": true, "relativeScores": true,
"textAnalyzer": "libpostal", "textAnalyzer": "libpostal",
"services": { "services": {

3
app.js

@ -16,9 +16,6 @@ app.use( require('./middleware/jsonp') );
/** ----------------------- routes ----------------------- **/ /** ----------------------- routes ----------------------- **/
var legacy = require('./routes/legacy');
legacy.addRoutes(app, peliasConfig.api);
var v1 = require('./routes/v1'); var v1 = require('./routes/v1');
v1.addRoutes(app, peliasConfig); v1.addRoutes(app, peliasConfig);

1
package.json

@ -43,7 +43,6 @@
"elasticsearch": "^12.0.1", "elasticsearch": "^12.0.1",
"elasticsearch-exceptions": "0.0.4", "elasticsearch-exceptions": "0.0.4",
"express": "^4.8.8", "express": "^4.8.8",
"express-http-proxy": "^0.11.0",
"extend": "^3.0.1", "extend": "^3.0.1",
"geojson": "^0.4.0", "geojson": "^0.4.0",
"@mapbox/geojson-extent": "^0.3.1", "@mapbox/geojson-extent": "^0.3.1",

34
routes/legacy.js

@ -1,34 +0,0 @@
var proxy = require('express-http-proxy');
function addRoutes(app, peliasConfig) {
var sendToLegacy;
if (!peliasConfig.hasOwnProperty('legacyUrl')) {
sendToLegacy = function redirectToV1(req, res, next) {
res.redirect(301, '/v1');
};
}
else {
sendToLegacy = proxy(peliasConfig.legacyUrl);
}
// api root
app.get( '/', sendToLegacy );
// place API
app.get( '/place', sendToLegacy);
// suggest APIs
app.get( '/suggest', sendToLegacy );
app.get( '/suggest/nearby', sendToLegacy );
app.get( '/suggest/coarse',sendToLegacy );
// search APIs
app.get( '/search', sendToLegacy);
app.get( '/search/coarse', sendToLegacy);
// reverse API
app.get( '/reverse', sendToLegacy );
}
module.exports.addRoutes = addRoutes;

2
schema.js

@ -12,14 +12,12 @@ const Joi = require('joi');
// optional: // optional:
// * api.accessLog (string) // * api.accessLog (string)
// * api.relativeScores (boolean) // * api.relativeScores (boolean)
// * api.legacyUrl (string)
// * api.localization (flipNumberAndStreetCountries is array of 3 character strings) // * api.localization (flipNumberAndStreetCountries is array of 3 character strings)
module.exports = Joi.object().keys({ module.exports = Joi.object().keys({
api: Joi.object().keys({ api: Joi.object().keys({
version: Joi.string(), version: Joi.string(),
indexName: Joi.string(), indexName: Joi.string(),
host: Joi.string(), host: Joi.string(),
legacyUrl: Joi.string(),
accessLog: Joi.string(), accessLog: Joi.string(),
relativeScores: Joi.boolean(), relativeScores: Joi.boolean(),
requestRetries: Joi.number().integer().min(0), requestRetries: Joi.number().integer().min(0),

24
test/unit/schema.js

@ -12,7 +12,6 @@ module.exports.tests.completely_valid = (test, common) => {
version: 'version value', version: 'version value',
indexName: 'index name value', indexName: 'index name value',
host: 'host value', host: 'host value',
legacyUrl: 'legacyUrl value',
accessLog: 'accessLog value', accessLog: 'accessLog value',
relativeScores: true, relativeScores: true,
localization: { localization: {
@ -160,29 +159,6 @@ module.exports.tests.api_validation = (test, common) => {
}); });
test('non-string api.legacyUrl should throw error', (t) => {
[null, 17, {}, [], true].forEach((value) => {
var config = {
api: {
version: 'version value',
indexName: 'index name value',
host: 'host value',
legacyUrl: value
},
esclient: {}
};
const result = Joi.validate(config, schema);
t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"legacyUrl" must be a string');
});
t.end();
});
test('non-string api.accessLog should throw error', (t) => { test('non-string api.accessLog should throw error', (t) => {
[null, 17, {}, [], true].forEach((value) => { [null, 17, {}, [], true].forEach((value) => {
var config = { var config = {

Loading…
Cancel
Save