Browse Source

Fix missing legacyUrl behavior

pull/210/head
Diana Shkolnikov 9 years ago
parent
commit
2b9fbdfd10
  1. 1
      app.js
  2. 11
      routes/legacy.js
  3. 9
      routes/v1.js

1
app.js

@ -15,6 +15,7 @@ app.use( require('./middleware/cors') );
app.use( require('./middleware/jsonp') ); app.use( require('./middleware/jsonp') );
/** ----------------------- routes ----------------------- **/ /** ----------------------- routes ----------------------- **/
var legacy = require('./routes/legacy'); var legacy = require('./routes/legacy');
legacy.addRoutes(app, peliasConfig); legacy.addRoutes(app, peliasConfig);

11
routes/legacy.js

@ -1,11 +1,16 @@
var proxy = require('express-http-proxy'); var proxy = require('express-http-proxy');
function addRoutes(app, peliasConfig) { function addRoutes(app, peliasConfig) {
var sendToLegacy;
if (!peliasConfig.hasOwnProperty('legacyUrl')) { if (!peliasConfig.hasOwnProperty('legacyUrl')) {
return; sendToLegacy = function doNothing(req, res, next) {
next(new Error('Invalid path, no legacy proxy specified'));
};
}
else {
sendToLegacy = proxy(peliasConfig.legacyUrl);
} }
var sendToLegacy = proxy(peliasConfig.legacyUrl);
// api root // api root
app.get( '/', sendToLegacy ); app.get( '/', sendToLegacy );

9
routes/v1.js

@ -1,4 +1,5 @@
var reverseQuery = require('./query/reverse'); var Router = require('express').Router;
var reverseQuery = require('../query/reverse');
/** ----------------------- sanitisers ----------------------- **/ /** ----------------------- sanitisers ----------------------- **/
var sanitisers = { var sanitisers = {
@ -18,9 +19,9 @@ var controllers = {
/** ----------------------- controllers ----------------------- **/ /** ----------------------- controllers ----------------------- **/
var postProc = { var postProc = {
renamePlacenames: require('./middleware/renamePlacenames'), renamePlacenames: require('../middleware/renamePlacenames'),
geocodeJSON: require('./middleware/geocodeJSON'), geocodeJSON: require('../middleware/geocodeJSON'),
sendJSON: require('./middleware/sendJSON') sendJSON: require('../middleware/sendJSON')
}; };
/** /**

Loading…
Cancel
Save