diff --git a/app.js b/app.js index 278d666c..21aa2856 100644 --- a/app.js +++ b/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') ); diff --git a/routes/v1.js b/routes/v1.js new file mode 100644 index 00000000..5c57646c --- /dev/null +++ b/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;