p-meier / hapi-api-version

An API versioning plugin for hapi.
Apache License 2.0
74 stars 26 forks source link

Fix '/' endpoint and stripTrailingSlash compatibility #25

Closed CleanAshen closed 5 years ago

CleanAshen commented 5 years ago

When using the server setting stripTrailingSlash and serving and endpoint at '/', hapi-api-version would search for v2 at '/v2/'. This route is impossible when stripTrailingSlash is set to true in Hapi, so the fallback default route would be served. This patch adds a new test showing the issue and a fix so that '/' will serve at '/v2'.

CleanAshen commented 5 years ago

Thanks @timcosta , I see your concern, I definitely would have been introducing breaking changes for those not using stripTrailingSlash.

I wrote a couple more tests to try to cover the additional cases I could think of. I also changed the code slightly to make a different determination of how to perform the path versioning based on whether stripTrailingSlash has been set. This should avoid breaking changes.

Thanks for maintaining the repo! I'm glad I can finally start making some contributions to open source.