Browse Source

always inject backend instead of require'ing inside

pull/782/head
Stephen Hess 8 years ago
parent
commit
00234265e6
  1. 4
      controller/place.js
  2. 5
      controller/search.js
  3. 15
      routes/v1.js

4
controller/place.js

@ -2,10 +2,6 @@ var service = { mget: require('../service/mget') };
var logger = require('pelias-logger').get('api');
function setup( config, backend ){
// allow overriding of dependencies
backend = backend || require('../src/backend');
function controller( req, res, next ){
// do not run controller when a request

5
controller/search.js

@ -5,11 +5,6 @@ var logger = require('pelias-logger').get('api');
var logging = require( '../helper/logging' );
function setup( config, backend, query ){
// allow overriding of dependencies
backend = backend || require('../src/backend');
query = query || require('../query/search');
function controller( req, res, next ){
// do not run controller when a request
// validation error has occurred.

15
routes/v1.js

@ -1,5 +1,6 @@
var Router = require('express').Router;
var reverseQuery = require('../query/reverse');
var backend = require('../src/backend');
/** ----------------------- sanitizers ----------------------- **/
var sanitizers = {
@ -77,9 +78,9 @@ function addRoutes(app, peliasConfig) {
// 2nd parameter is `backend` which gets initialized internally
// 3rd parameter is which query module to use, use fallback/geodisambiguation
// first, then use original search strategy if first query didn't return anything
controllers.search(peliasConfig, undefined, queries.libpostal),
controllers.search(peliasConfig, backend, queries.libpostal),
sanitizers.search_fallback.middleware,
controllers.search(peliasConfig, undefined, queries.fallback_to_old_prod),
controllers.search(peliasConfig, backend, queries.fallback_to_old_prod),
postProc.trimByGranularity(),
postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig),
@ -97,7 +98,7 @@ function addRoutes(app, peliasConfig) {
structured: createRouter([
sanitizers.structured_geocoding.middleware,
middleware.calcSize(),
controllers.search(peliasConfig, undefined, queries.structured_geocoding),
controllers.search(peliasConfig, backend, queries.structured_geocoding),
postProc.trimByGranularityStructured(),
postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig),
@ -114,7 +115,7 @@ function addRoutes(app, peliasConfig) {
]),
autocomplete: createRouter([
sanitizers.autocomplete.middleware,
controllers.search(peliasConfig, null, require('../query/autocomplete')),
controllers.search(peliasConfig, backend, require('../query/autocomplete')),
postProc.distances('focus.point.'),
postProc.confidenceScores(peliasConfig),
postProc.dedupe(),
@ -130,7 +131,7 @@ function addRoutes(app, peliasConfig) {
reverse: createRouter([
sanitizers.reverse.middleware,
middleware.calcSize(),
controllers.search(peliasConfig, undefined, reverseQuery),
controllers.search(peliasConfig, backend, reverseQuery),
postProc.distances('point.'),
// reverse confidence scoring depends on distance from origin
// so it must be calculated first
@ -148,7 +149,7 @@ function addRoutes(app, peliasConfig) {
nearby: createRouter([
sanitizers.nearby.middleware,
middleware.calcSize(),
controllers.search(peliasConfig, undefined, reverseQuery),
controllers.search(peliasConfig, backend, reverseQuery),
postProc.distances('point.'),
// reverse confidence scoring depends on distance from origin
// so it must be calculated first
@ -165,7 +166,7 @@ function addRoutes(app, peliasConfig) {
]),
place: createRouter([
sanitizers.place.middleware,
controllers.place(peliasConfig),
controllers.place(peliasConfig, backend),
postProc.accuracy(),
postProc.localNamingConventions(),
postProc.renamePlacenames(),

Loading…
Cancel
Save