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

15
routes/v1.js

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

Loading…
Cancel
Save