Browse Source

Add V1 routes with proxying to legacy

Using the semver middleware, handle requests to the new v1 api as well
as legacy routes.
pull/213/head
Julian Simioni 10 years ago
parent
commit
e3961187b2
  1. 3
      app.js
  2. 40
      routes/v1.js

3
app.js

@ -17,6 +17,9 @@ app.use( require('./middleware/jsonp') );
var legacy = require('./routes/legacy');
legacy.addRoutes(app, peliasConfig);
var v1 = require('./routes/v1');
v1.addRoutes(app, peliasConfig);
/** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') );

40
routes/v1.js

@ -0,0 +1,40 @@
/** ----------------------- 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');
/** ---------------------- routing --------------------------- **/
var routers = {};
routers.semver = require('../middleware/semver');
/** ----------------------- 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( '/:vr/', controllers.index() );
// place API
app.get( '/:vr/place', sanitisers.place.middleware, controllers.place() );
// suggest APIs
app.get( '/:vr/suggest', sanitisers.search.middleware, controllers.search() );
app.get( '/:vr/suggest/nearby', sanitisers.suggest.middleware, controllers.search() );
app.get( '/:vr/suggest/coarse', sanitisers.coarse.middleware, controllers.search() );
// search APIs
app.get( '/:vr/search', routers.semver(peliasConfig), sanitisers.search.middleware, controllers.search() );
app.get( '/:vr/search/coarse', sanitisers.coarse.middleware, controllers.search() );
// reverse API
app.get( '/:vr/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('../query/reverse')) );
}
module.exports.addRoutes = addRoutes;
Loading…
Cancel
Save