From 047162751a0e7cdf1249081cc82de030d1bc9f42 Mon Sep 17 00:00:00 2001 From: Andrew Olson Date: Wed, 2 Mar 2016 15:07:00 -0500 Subject: [PATCH] configure paths from the basePath version --- api/swagger/swagger.yaml | 2 +- app.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 20b647f..21453e2 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -3,7 +3,7 @@ info: version: "0.50.0" title: Gramene API for release 50 # basePath prefixes all resource paths -basePath: / +basePath: /v50 # during dev, should point to your local machine #host: localhost:10010/{basePath} # diff --git a/app.js b/app.js index eba54b4..ea85b2a 100644 --- a/app.js +++ b/app.js @@ -19,18 +19,20 @@ var config = { SwaggerExpress.create(config, function (err, swaggerExpress) { if (err) { throw err; } + var basePath = swaggerExpress.runner.swagger.basePath; // define routes for documentation - app.get('/', function (req, res, next) { // redirect to /docs with the correct schema - res.redirect('/docs?url=/swagger'); + app.get(basePath, function (req, res, next) { // redirect to /docs with the correct schema + res.redirect(basePath+'/docs?url='+basePath+'/swagger'); }); - app.use('/docs', express.static('node_modules/swagger-ui/dist')); + app.use(basePath+'/docs', express.static('node_modules/swagger-ui/dist')); // install swagger server middleware swaggerExpress.register(app); // start it up - var port = process.env.PORT || 10011; + var version = +basePath.match(/\d+/); + var port = process.env.PORT || 10000 + version; app.listen(port); console.log('Listening on', port);