Browse Source

Merge branch 'simple-semver'

pull/214/head
Julian Simioni 9 years ago
parent
commit
3b5fd79102
  1. 36
      app.js
  2. 1
      package.json
  3. 29
      routes/legacy.js
  4. 36
      routes/v1.js

36
app.js

@ -12,41 +12,13 @@ app.use( require('./middleware/headers') );
app.use( require('./middleware/cors') );
app.use( require('./middleware/jsonp') );
/** ----------------------- sanitisers ----------------------- **/
var sanitisers = {};
sanitisers.place = require('./sanitiser/place');
sanitisers.suggest = require('./sanitiser/suggest');
sanitisers.search = require('./sanitiser/search');
sanitisers.coarse = require('./sanitiser/coarse');
sanitisers.reverse = require('./sanitiser/reverse');
/** ----------------------- controllers ----------------------- **/
var controllers = {};
controllers.index = require('./controller/index');
controllers.place = require('./controller/place');
controllers.search = require('./controller/search');
/** ----------------------- routes ----------------------- **/
var legacy = require('./routes/legacy');
legacy.addRoutes(app, peliasConfig);
// api root
app.get( '/', controllers.index() );
// place API
app.get( '/place', sanitisers.place.middleware, controllers.place() );
// suggest APIs
app.get( '/suggest', sanitisers.search.middleware, controllers.search() );
app.get( '/suggest/nearby', sanitisers.suggest.middleware, controllers.search() );
app.get( '/suggest/coarse', sanitisers.coarse.middleware, controllers.search() );
// search APIs
app.get( '/search', sanitisers.search.middleware, controllers.search() );
app.get( '/search/coarse', sanitisers.coarse.middleware, controllers.search() );
// reverse API
app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('./query/reverse')) );
var v1 = require('./routes/v1');
v1.addRoutes(app, peliasConfig);
/** ----------------------- error middleware ----------------------- **/

1
package.json

@ -37,6 +37,7 @@
"async": "^0.9.0",
"cluster2": "git://github.com/missinglink/cluster2.git#node_zero_twelve",
"express": "^4.8.8",
"express-http-proxy": "^0.6.0",
"extend": "2.0.1",
"geojson": "^0.2.1",
"geojson-extent": "^0.3.1",

29
routes/legacy.js

@ -0,0 +1,29 @@
var proxy = require('express-http-proxy');
function addRoutes(app, peliasConfig) {
if (!peliasConfig.hasOwnProperty('legacyUrl')) {
return;
}
var sendToLegacy = proxy(peliasConfig.legacyUrl);
// api root
app.get( '/', sendToLegacy );
// place API
app.get( '/place', sendToLegacy);
// suggest APIs
app.get( '/suggest', sendToLegacy );
app.get( '/suggest/nearby', sendToLegacy );
app.get( '/suggest/coarse',sendToLegacy );
// search APIs
app.get( '/search', sendToLegacy);
app.get( '/search/coarse', sendToLegacy);
// reverse API
app.get( '/reverse', sendToLegacy );
}
module.exports.addRoutes = addRoutes;

36
routes/v1.js

@ -0,0 +1,36 @@
/** ----------------------- sanitisers ----------------------- **/
var sanitisers = {};
sanitisers.place = require('../sanitiser/place');
sanitisers.suggest = require('../sanitiser/suggest');
sanitisers.search = require('../sanitiser/search');
sanitisers.coarse = require('../sanitiser/coarse');
sanitisers.reverse = require('../sanitiser/reverse');
/** ----------------------- controllers ----------------------- **/
var controllers = {};
controllers.index = require('../controller/index');
controllers.place = require('../controller/place');
controllers.search = require('../controller/search');
function addRoutes(app, peliasConfig) {
// api root
app.get( '/v1/', controllers.index() );
// place API
app.get( '/v1/place', sanitisers.place.middleware, controllers.place() );
// suggest APIs
app.get( '/v1/suggest', sanitisers.search.middleware, controllers.search() );
app.get( '/v1/suggest/nearby', sanitisers.suggest.middleware, controllers.search() );
app.get( '/v1/suggest/coarse', sanitisers.coarse.middleware, controllers.search() );
// search APIs
app.get( '/v1/search', sanitisers.search.middleware, controllers.search() );
app.get( '/v1/search/coarse', sanitisers.coarse.middleware, controllers.search() );
// reverse API
app.get( '/v1/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('../query/reverse')) );
}
module.exports.addRoutes = addRoutes;
Loading…
Cancel
Save