Browse Source

Merge pull request #161 from pelias/master

production merge
pull/160/merge
Peter Johnson a.k.a. insertcoffee 9 years ago
parent
commit
2de24ef40d
  1. 1
      .travis.yml
  2. 1
      app.js
  3. 13
      middleware/408.js
  4. 2
      middleware/500.js
  5. 14
      package.json
  6. 7
      query/reverse.js
  7. 4
      test/unit/query/reverse.js
  8. 14
      test/unit/query/search.js

1
.travis.yml

@ -2,3 +2,4 @@ language: node_js
script: "npm run unit"
node_js:
- "0.10"
sudo: false

1
app.js

@ -52,6 +52,7 @@ app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined
/** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') );
app.use( require('./middleware/408') );
app.use( require('./middleware/500') );
module.exports = app;

13
middleware/408.js

@ -0,0 +1,13 @@
// handle time out errors
function middleware(err, req, res, next) {
res.header('Cache-Control','no-cache');
if( res.statusCode === 408 || (err.message.toLowerCase().indexOf('request timeout') !== -1) ){
res.status(408);
res.json({ error: err && typeof err.message === 'string' ? err.message : 'request time out' });
} else {
next(err);
}
}
module.exports = middleware;

2
middleware/500.js

@ -5,7 +5,7 @@ function middleware(err, req, res, next) {
logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack );
res.header('Cache-Control','no-cache');
if( res.statusCode < 400 ){ res.status(500); }
res.json({ error: typeof err === 'string' ? err : 'internal server error' });
res.json({ error: err && typeof err.message === 'string' ? err.message : 'internal server error' });
}
module.exports = middleware;

14
package.json

@ -1,7 +1,7 @@
{
"name": "pelias-api",
"author": "mapzen",
"version": "2.0.0",
"version": "2.1.0",
"description": "Pelias API",
"homepage": "https://github.com/pelias/api",
"license": "MIT",
@ -37,16 +37,16 @@
"express": "^4.8.8",
"geojson": "^0.2.1",
"geojson-extent": "^0.3.1",
"geopipes-elasticsearch-backend": "0.0.12",
"geopipes-elasticsearch-backend": "^0.2.0",
"is-object": "^1.0.1",
"markdown": "0.5.0",
"pelias-esclient": "0.0.25",
"pelias-logger": "^0.0.8",
"through2": "0.6.5",
"microtime": "1.4.0",
"morgan": "1.5.2",
"pelias-config": "^0.1.4",
"microtime": "1.4.0",
"pelias-suggester-pipeline": "2.0.2"
"pelias-esclient": "0.0.25",
"pelias-logger": "^0.0.8",
"pelias-suggester-pipeline": "2.0.2",
"through2": "0.6.5"
},
"devDependencies": {
"ciao": "^0.3.4",

7
query/reverse.js

@ -9,7 +9,12 @@ function generate( params ){
lon: params.lon
};
var query = queries.distance( centroid, { size: params.size || 1 } );
var query = queries.distance( centroid, {
size: params.size || 1,
sort: true,
distance: '500km'
});
query.sort = query.sort.concat( sort( params ) );
if ( params.categories && params.categories.length > 0 ) {

4
test/unit/query/reverse.js

@ -78,7 +78,7 @@ module.exports.tests.query = function(test, common) {
'must': [
{
'geo_distance': {
'distance': '50km',
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,
@ -139,7 +139,7 @@ module.exports.tests.query = function(test, common) {
'must': [
{
'geo_distance': {
'distance': '50km',
'distance': '500km',
'distance_type': 'plane',
'optimize_bbox': 'indexed',
'_cache': true,

14
test/unit/query/search.js

@ -220,19 +220,7 @@ module.exports.tests.query = function(test, common) {
}
}
},
'sort': [
'_score',
{
'_geo_distance': {
'center_point': {
'lat': 29.49136,
'lon': -82.50622
},
'order': 'asc',
'unit': 'km'
}
}
].concat(sort.slice(1)),
'sort': ['_score'].concat(sort.slice(1)),
'size': 10,
'track_scores': true
};

Loading…
Cancel
Save