Skip to content

Commit

Permalink
Prevent addition of :host/:id to routes with $namespace but no $provi…
Browse files Browse the repository at this point in the history
…derParams (#30)

* routes including placeholder `$namespace` no longer automatically get the `:host/:id` fragment
* Bump koop-output-geoservices version dependency
  • Loading branch information
rgwozdz authored May 9, 2018
1 parent e6efa6a commit d624fbf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Fixed
* Routes with a $namespace placeholder require a $providerParams placeholder to also receive the `:host/:id` URL fragment.

## [3.6.0] - 2018-04-25
### Added
* helper module and function to create route paths with decoration based on passed options
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"express": "^4.14.1",
"koop-cache-memory": "^1.0.2",
"koop-localfs": "^1.1.1",
"koop-output-geoservices": "^1.0.0",
"koop-output-geoservices": "^1.2.0",
"lodash": "^4.17.10"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function composeRouteString(routePath, namespace, opts) {
if (routePath.includes(namespacePlaceholder) && routePath.includes(paramsPlaceholder)) {
return path.posix.join('/', routePath.replace(namespacePlaceholder, namespace).replace(paramsPlaceholder, paramFragment))
} else if (routePath.includes(namespacePlaceholder)) {
return path.posix.join('/', routePath.replace(namespacePlaceholder, path.posix.join(namespace, paramFragment)))
return path.posix.join('/', routePath.replace(namespacePlaceholder, namespace))
} else if (routePath.includes(paramsPlaceholder)) {
return path.posix.join('/', namespace, routePath.replace(paramsPlaceholder, paramFragment))
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ function bindPluginOverrides (provider, controller, server, pluginRoutes) {
const name = provider.namespace || provider.plugin_name || provider.name
const namespace = name.replace(/\s/g, '').toLowerCase()
pluginRoutes.forEach(route => {
let fullRoute = helpers.composeRouteString(route.path, namespace, {hosts: provider.hosts, disableIdParam: provider.disableIdParam, absolutePath: route.absolutePath})
let fullRoute = helpers.composeRouteString(route.path, namespace, {
hosts: provider.hosts,
disableIdParam: provider.disableIdParam,
absolutePath: route.absolutePath
})
route.methods.forEach(method => {
try {
console.log(`provider=${provider.name} fullRoute:${fullRoute}`)
Expand Down
2 changes: 1 addition & 1 deletion test/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Tests for helper functions', function () {

it('create route with templated $namespace$ substring', function () {
let fullRoute = helpers.composeRouteString('$namespace/rest/services/FeatureServer/:layer/:method','test')
fullRoute.should.equal('/test/:id/rest/services/FeatureServer/:layer/:method')
fullRoute.should.equal('/test/rest/services/FeatureServer/:layer/:method')
})

it('create route with templated $namespace$ substring', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Index tests for registering providers', function () {
koop.register(provider)
const routeCount = (koop.server._router.stack.length)
// TODO make this test less brittle
routeCount.should.equal(38)
routeCount.should.equal(58)
})
})
})

0 comments on commit d624fbf

Please sign in to comment.