Browse Source

Add default route redirecting to /v1

This makes the root URL of the API a bit more friendly

Fixes https://github.com/pelias/api/issues/961
pull/962/head
Julian Simioni 7 years ago
parent
commit
fb9b76ef6f
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 5
      app.js
  2. 12
      routes/default.js

5
app.js

@ -1,4 +1,3 @@
var app = require('express')();
var peliasConfig = require( 'pelias-config' ).generate(require('./schema'));
@ -16,6 +15,10 @@ app.use( require('./middleware/jsonp') );
/** ----------------------- routes ----------------------- **/
var defaultRoutes = require('./routes/default');
defaultRoutes.addRoutes(app);
var v1 = require('./routes/v1');
v1.addRoutes(app, peliasConfig);

12
routes/default.js

@ -0,0 +1,12 @@
// set up routes that are outside any particular API version
function addRoutes(app) {
function redirectToV1(req, res, next) {
res.redirect(301, '/v1');
}
// default root URL traffic to V1 root
// which has a link to the readme and other helpful info
app.get('/', redirectToV1);
}
module.exports.addRoutes = addRoutes;
Loading…
Cancel
Save