From 8c5ddec0c99d745ecbae8e881c168c65bb68c545 Mon Sep 17 00:00:00 2001 From: Sushin Pv Date: Sat, 13 Jun 2020 12:13:31 +0530 Subject: [PATCH] Bug fix while using customer basePath When you use a basePath like `/api/` then the route won't ever hit, because these was an unwanted splice was happening on the required url Example: basePath: /api/ defaultVersion: 2 Requested Url : /users then the final url was : /api/v2rs This issue is fixed --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6b9cd17..82c51e8 100644 --- a/index.js +++ b/index.js @@ -133,7 +133,7 @@ exports.register = (server, options) => { requestedVersion = options.defaultVersion; } - const versionedPath = options.basePath + 'v' + requestedVersion + request.path.slice(options.basePath.length - 1); + const versionedPath = options.basePath + 'v' + requestedVersion + request.path; let method = request.method; if (request.method === 'options') { @@ -147,7 +147,7 @@ exports.register = (server, options) => { const route = server.match(method, versionedPath); if (route && route.path.indexOf(options.basePath + 'v' + requestedVersion + '/') === 0) { - request.setUrl(options.basePath + 'v' + requestedVersion + request.path.slice(options.basePath.length - 1) + (request.url.search || '')); //required to preserve query parameters + request.setUrl(options.basePath + 'v' + requestedVersion + request.path + (request.url.search || '')); //required to preserve query parameters } //Set version for usage in handler