Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/services/http-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var fs = require('fs');
var proxyMiddleware = require('http-proxy-middleware');
var path = require('path');
var bodyParser = require('body-parser');
var rewriter = require('express-urlrewrite');

/**
* Get remote address of the client.
Expand Down Expand Up @@ -218,6 +219,11 @@ function httpServiceFactory(
)
);

//re-route common and current
var versionPath = configuration.get('versionBase') || '1.1';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keedya I think we should add an assert or some other type of check to verify that versionBase is set to a valid value.

app.use(rewriter('/api/current/*', '/api/' + versionPath + '/$1'));
app.use(rewriter('/api/common/*', '/api/' + versionPath + '/$1'));

// API Docs Directory
app.use('/docs',
express.static(
Expand All @@ -236,8 +242,6 @@ function httpServiceFactory(
// mount ./login only when authentication is enabled
app.use(injector.get('Http.Api.Login'));
app.all('/api/1.1/*', authService.authMiddlewareJwt.bind(authService));
app.all('/api/common/*', authService.authMiddlewareJwt.bind(authService));
app.all('/api/current/*', authService.authMiddlewareJwt.bind(authService));
}

// Mount API Routers
Expand All @@ -251,7 +255,7 @@ function httpServiceFactory(
}

router.mount();
app.use(/\/api\/(common|current|1\.1)/, router);
app.use(/\/api\/1\.1/, router);
});

if (endpoint.httpsEnabled) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"url-parse": "~1.1.1",
"validator": "^5.2.0",
"ws": "^0.8.0",
"fs-extra": "~0.30.0"
"fs-extra": "~0.30.0",
"express-urlrewrite": "~1.2.0"
},
"devDependencies": {
"apidoc": "^0.12.1",
Expand Down