Browse Source

seperating suggest and search sanitizers because suggest requires geoBias (lat/lon) until ES 2.0.0 lands.

pull/92/head
Harish Krishna 10 years ago
parent
commit
217a5c1049
  1. 2
      app.js
  2. 26
      sanitiser/search.js
  3. 5
      sanitiser/suggest.js

2
app.js

@ -12,7 +12,7 @@ app.use( require('./middleware/jsonp') );
var sanitisers = {}; var sanitisers = {};
sanitisers.doc = require('./sanitiser/doc'); sanitisers.doc = require('./sanitiser/doc');
sanitisers.suggest = require('./sanitiser/suggest'); sanitisers.suggest = require('./sanitiser/suggest');
sanitisers.search = sanitisers.suggest; sanitisers.search = require('./sanitiser/search');
sanitisers.coarse = require('./sanitiser/coarse'); sanitisers.coarse = require('./sanitiser/coarse');
sanitisers.reverse = require('./sanitiser/reverse'); sanitisers.reverse = require('./sanitiser/reverse');

26
sanitiser/search.js

@ -0,0 +1,26 @@
var logger = require('../src/logger'),
_sanitize = require('../sanitiser/_sanitize'),
sanitizers = {
input: require('../sanitiser/_input'),
size: require('../sanitiser/_size'),
layers: require('../sanitiser/_layers'),
latlonzoom: require('../sanitiser/_geo')
};
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();
});
};

5
sanitiser/suggest.js

@ -5,7 +5,10 @@ var logger = require('../src/logger'),
input: require('../sanitiser/_input'), input: require('../sanitiser/_input'),
size: require('../sanitiser/_size'), size: require('../sanitiser/_size'),
layers: require('../sanitiser/_layers'), layers: require('../sanitiser/_layers'),
latlonzoom: require('../sanitiser/_geo') latlonzoom: function( req ) {
var geo = require('../sanitiser/_geo');
return geo(req, true);
}
}; };
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); }; var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };

Loading…
Cancel
Save