Browse Source

search/coarse endpoint

pull/63/head
Harish Krishna 10 years ago
parent
commit
eeecbf71dc
  1. 3
      app.js
  2. 30
      sanitiser/coarse.js

3
app.js

@ -14,6 +14,7 @@ var sanitisers = {};
sanitisers.doc = require('./sanitiser/doc');
sanitisers.suggest = require('./sanitiser/suggest');
sanitisers.search = sanitisers.suggest;
sanitisers.coarse = require('./sanitiser/coarse');
sanitisers.reverse = require('./sanitiser/reverse');
/** ----------------------- controllers ----------------------- **/
@ -47,6 +48,8 @@ app.get( '/search', sanitisers.search.middleware, controllers.search() );
// reverse API
app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('./query/reverse')) );
// coarse API
app.get( '/search/coarse', sanitisers.coarse.middleware, controllers.search() );
/** ----------------------- error middleware ----------------------- **/

30
sanitiser/coarse.js

@ -0,0 +1,30 @@
var logger = require('../src/logger'),
_sanitize = require('../sanitiser/_sanitize'),
sanitizers = {
input: require('../sanitiser/_input'),
size: require('../sanitiser/_size'),
layers: function( req ) {
req.query.layers = 'admin';
var layers = require('../sanitiser/_layers');
return layers(req);
},
latlonzoom: require('../sanitiser/_latlonzoom')
};
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };
// export sanitize for testing
module.exports.sanitize = sanitize;
// middleware
module.exports.middleware = function( req, res, next ){
sanitize( req, function( err, clean ){
if( err ){
res.status(400); // 400 Bad Request
return next(err);
}
req.clean = clean;
next();
});
};
Loading…
Cancel
Save