From 55eaa86c3923f12c27010446216c7cdf15c265d8 Mon Sep 17 00:00:00 2001 From: Lee Keun Won Date: Wed, 23 Jun 2021 12:10:05 +0900 Subject: [PATCH 1/6] Resolves an issue where the path key is set to a different path if it is duplicated in the URL path Resolves an issue where the path key is set to a different path if it is duplicated in the URL path ex > { '/product' : 'http://product-service/' '/example' : 'http://product-service/' } call url : http://example.com/example/path/product match route url : 'http://product-service/' --- src/router.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/router.ts b/src/router.ts index d2e63505..c2fa8e35 100644 --- a/src/router.ts +++ b/src/router.ts @@ -24,10 +24,16 @@ function getTargetFromProxyTable(req, table) { for (const [key] of Object.entries(table)) { if (containsPath(key)) { - if (hostAndPath.indexOf(key) > -1) { + if(/^\//.test(key)) { + if(path.startsWith(key)) { + result = table[key]; + logger.debug('[HPM] Router table match path only : "%s"', key); + break; + } + } else if (hostAndPath.indexOf(key) > -1) { // match 'localhost:3000/api' result = table[key]; - logger.debug('[HPM] Router table match: "%s"', key); + logger.debug('[HPM] Router table match host and path: "%s"', key); break; } } else { From e86c3b0752d03f18c8ca65dfafc048ea51ff3685 Mon Sep 17 00:00:00 2001 From: Lee Keun Won Date: Thu, 24 Jun 2021 08:41:22 +0900 Subject: [PATCH 2/6] Update router.spec.ts another route key is use in url path test --- test/unit/router.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/router.spec.ts b/test/unit/router.spec.ts index fa554f71..42944bb4 100644 --- a/test/unit/router.spec.ts +++ b/test/unit/router.spec.ts @@ -157,5 +157,13 @@ describe('router unit test', () => { return expect(result).resolves.toBe('http://localhost:6006'); }); }); + + describe('matching order of router config', () => { + it('should return another route key is use in url path configured', () => { + fakeReq.url = '/some/rest/path'; + result = getTarget(fakeReq, proxyOptionWithRouter); + return expect(result).resolves.toBe('http://localhost:6007'); + }); + }); }); }); From a5070e7aec416a691e20b6f5ade8ebaf9339bffb Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Thu, 24 Jun 2021 00:44:25 +0000 Subject: [PATCH 3/6] fix: upgrade @types/http-proxy from 1.17.5 to 1.17.6 Snyk has created this PR to upgrade @types/http-proxy from 1.17.5 to 1.17.6. See this package in npm: See this project in Snyk: https://app.snyk.io/org/lovelgw/project/8d01a776-ebaf-4878-bab0-56d838168105?utm_source=github&utm_medium=upgrade-pr --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 10daffed..3470dc31 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "ws": "^7.4.6" }, "dependencies": { - "@types/http-proxy": "^1.17.5", + "@types/http-proxy": "^1.17.6", "http-proxy": "^1.18.1", "is-glob": "^4.0.1", "is-plain-obj": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index e058ff74..64252904 100644 --- a/yarn.lock +++ b/yarn.lock @@ -810,10 +810,10 @@ dependencies: "@types/node" "*" -"@types/http-proxy@^1.17.5": - version "1.17.5" - resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.5.tgz#c203c5e6e9dc6820d27a40eb1e511c70a220423d" - integrity sha512-GNkDE7bTv6Sf8JbV2GksknKOsk7OznNYHSdrtvPJXO0qJ9odZig6IZKUi5RFGi6d1bf6dgIAe4uXi3DBc7069Q== +"@types/http-proxy@^1.17.6": + version "1.17.6" + resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.6.tgz#62dc3fade227d6ac2862c8f19ee0da9da9fd8616" + integrity sha512-+qsjqR75S/ib0ig0R9WN+CDoZeOBU6F2XLewgC4KVgdXiNHiKKHFEMRHOrs5PbYE97D5vataw5wPj4KLYfUkuQ== dependencies: "@types/node" "*" From a25d41110c45ec602235278cdb6d8f209aec1bd7 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Fri, 20 Aug 2021 02:49:16 +0000 Subject: [PATCH 4/6] fix: upgrade @types/http-proxy from 1.17.6 to 1.17.7 Snyk has created this PR to upgrade @types/http-proxy from 1.17.6 to 1.17.7. See this package in npm: See this project in Snyk: https://app.snyk.io/org/lovelgw/project/8d01a776-ebaf-4878-bab0-56d838168105?utm_source=github&utm_medium=upgrade-pr --- package.json | 2 +- yarn.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e1d36d0f..7385dcf2 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "ws": "^8.1.0" }, "dependencies": { - "@types/http-proxy": "^1.17.6", + "@types/http-proxy": "^1.17.7", "http-proxy": "^1.18.1", "is-glob": "^4.0.1", "is-plain-obj": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index e1e76bcc..b865debb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -814,7 +814,7 @@ dependencies: "@types/express" "*" -"@types/express-serve-static-core@^4.17.18", "@types/express-serve-static-core@^4.17.24": +"@types/express-serve-static-core@^4.17.18": version "4.17.24" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.24.tgz#ea41f93bf7e0d59cd5a76665068ed6aab6815c07" integrity sha512-3UJuW+Qxhzwjq3xhwXm2onQcFHn76frIYVbTu+kn24LFxI+dEhdfISDFovPB8VpEgW8oQCTpRuCe+0zJxB7NEA== @@ -840,10 +840,10 @@ dependencies: "@types/node" "*" -"@types/http-proxy@^1.17.6": - version "1.17.6" - resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.6.tgz#62dc3fade227d6ac2862c8f19ee0da9da9fd8616" - integrity sha512-+qsjqR75S/ib0ig0R9WN+CDoZeOBU6F2XLewgC4KVgdXiNHiKKHFEMRHOrs5PbYE97D5vataw5wPj4KLYfUkuQ== +"@types/http-proxy@^1.17.7": + version "1.17.7" + resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.7.tgz#30ea85cc2c868368352a37f0d0d3581e24834c6f" + integrity sha512-9hdj6iXH64tHSLTY+Vt2eYOGzSogC+JQ2H7bdPWkuh7KXP5qLllWx++t+K9Wk556c3dkDdPws/SpMRi0sdCT1w== dependencies: "@types/node" "*" @@ -926,7 +926,7 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== -"@types/serve-static@*", "@types/serve-static@^1.13.10": +"@types/serve-static@*": version "1.13.10" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9" integrity sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ== From 3b5d9d4817f16778a01866b088d62078217ed199 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Mon, 18 Oct 2021 04:10:15 +0000 Subject: [PATCH 5/6] fix: upgrade is-glob from 4.0.1 to 4.0.2 Snyk has created this PR to upgrade is-glob from 4.0.1 to 4.0.2. See this package in npm: See this project in Snyk: https://app.snyk.io/org/lovelgw/project/8d01a776-ebaf-4878-bab0-56d838168105?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- yarn.lock | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e1d36d0f..4d09342d 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "dependencies": { "@types/http-proxy": "^1.17.6", "http-proxy": "^1.18.1", - "is-glob": "^4.0.1", + "is-glob": "^4.0.2", "is-plain-obj": "^3.0.0", "micromatch": "^4.0.2" }, diff --git a/yarn.lock b/yarn.lock index e1e76bcc..667df490 100644 --- a/yarn.lock +++ b/yarn.lock @@ -814,7 +814,7 @@ dependencies: "@types/express" "*" -"@types/express-serve-static-core@^4.17.18", "@types/express-serve-static-core@^4.17.24": +"@types/express-serve-static-core@^4.17.18": version "4.17.24" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.24.tgz#ea41f93bf7e0d59cd5a76665068ed6aab6815c07" integrity sha512-3UJuW+Qxhzwjq3xhwXm2onQcFHn76frIYVbTu+kn24LFxI+dEhdfISDFovPB8VpEgW8oQCTpRuCe+0zJxB7NEA== @@ -926,7 +926,7 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== -"@types/serve-static@*", "@types/serve-static@^1.13.10": +"@types/serve-static@*": version "1.13.10" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9" integrity sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ== @@ -3102,6 +3102,13 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" +is-glob@^4.0.2: + version "4.0.3" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + is-number-like@^1.0.3: version "1.0.8" resolved "https://registry.yarnpkg.com/is-number-like/-/is-number-like-1.0.8.tgz#2e129620b50891042e44e9bbbb30593e75cfbbe3" From e3e9ebfba4f7103100f4fef56499474d9afb22b9 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Thu, 14 Apr 2022 22:09:16 +0000 Subject: [PATCH 6/6] fix: upgrade micromatch from 4.0.4 to 4.0.5 Snyk has created this PR to upgrade micromatch from 4.0.4 to 4.0.5. See this package in npm: See this project in Snyk: https://app.snyk.io/org/lovelgw/project/8d01a776-ebaf-4878-bab0-56d838168105?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- yarn.lock | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e1d36d0f..741c335d 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "http-proxy": "^1.18.1", "is-glob": "^4.0.1", "is-plain-obj": "^3.0.0", - "micromatch": "^4.0.2" + "micromatch": "^4.0.5" }, "engines": { "node": ">=12.0.0" diff --git a/yarn.lock b/yarn.lock index e1e76bcc..92548407 100644 --- a/yarn.lock +++ b/yarn.lock @@ -814,7 +814,7 @@ dependencies: "@types/express" "*" -"@types/express-serve-static-core@^4.17.18", "@types/express-serve-static-core@^4.17.24": +"@types/express-serve-static-core@^4.17.18": version "4.17.24" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.24.tgz#ea41f93bf7e0d59cd5a76665068ed6aab6815c07" integrity sha512-3UJuW+Qxhzwjq3xhwXm2onQcFHn76frIYVbTu+kn24LFxI+dEhdfISDFovPB8VpEgW8oQCTpRuCe+0zJxB7NEA== @@ -926,7 +926,7 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== -"@types/serve-static@*", "@types/serve-static@^1.13.10": +"@types/serve-static@*": version "1.13.10" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.10.tgz#f5e0ce8797d2d7cc5ebeda48a52c96c4fa47a8d9" integrity sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ== @@ -1394,7 +1394,7 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -braces@^3.0.1, braces@~3.0.2: +braces@^3.0.1, braces@^3.0.2, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -4053,6 +4053,14 @@ micromatch@^4.0.2, micromatch@^4.0.4: braces "^3.0.1" picomatch "^2.2.3" +micromatch@^4.0.5: + version "4.0.5" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" + integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== + dependencies: + braces "^3.0.2" + picomatch "^2.3.1" + mime-db@1.47.0: version "1.47.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.47.0.tgz#8cb313e59965d3c05cfbf898915a267af46a335c" @@ -4522,6 +4530,11 @@ picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3: resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.3.tgz#465547f359ccc206d3c48e46a1bcb89bf7ee619d" integrity sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg== +picomatch@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" + integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== + pify@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"