You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
696 B

10 years ago
var query = require('../query/suggest'),
backend = require('../src/backend');
10 years ago
function controller( req, res, next ){
10 years ago
// backend command
var cmd = {
index: 'pelias',
10 years ago
body: query( req.clean )
};
10 years ago
// query backend
backend().client.suggest( cmd, function( err, data ){
10 years ago
var docs = [];
10 years ago
// handle backend errors
if( err ){ return next( err ); }
// map response to a valid FeatureCollection
if( data && Array.isArray( data.pelias ) && data.pelias.length ){
docs = data['pelias'][0].options || [];
}
10 years ago
// respond
return res.status(200).json({
date: new Date().getTime(),
body: docs
});
});
10 years ago
}
module.exports = controller;