From a7322edff13dde21509667735f2692ef6322cca1 Mon Sep 17 00:00:00 2001 From: dpepin Date: Wed, 14 Feb 2024 12:05:15 -0500 Subject: [PATCH 1/2] fix(devCdn): removing extra / which created malformed url --- __tests__/server/utils/devCdnFactory.spec.js | 13 +- package-lock.json | 148 ++++--------------- package.json | 1 - src/server/utils/devCdnFactory.js | 15 +- 4 files changed, 44 insertions(+), 133 deletions(-) diff --git a/__tests__/server/utils/devCdnFactory.spec.js b/__tests__/server/utils/devCdnFactory.spec.js index 1bce1186..2d65d45a 100644 --- a/__tests__/server/utils/devCdnFactory.spec.js +++ b/__tests__/server/utils/devCdnFactory.spec.js @@ -524,18 +524,17 @@ describe('one-app-dev-cdn', () => { describe('modules', () => { it('gets remote modules', async () => { expect.assertions(5); - const fcdn = setupTest({ useLocalModules: false, appPort: 3000, - remoteModuleMapUrl: 'https://example.com/module-map.json', + remoteModuleMapUrl: 'https://example.com/static/module-map.json', + routePrefix: '/static', }); + fetch.mockReturnJsonOnce(defaultRemoteMap); fetch.mockReturnFileOnce('console.log("a");'); - const moduleMapResponse = await fcdn.inject() - .get('/module-map.json'); - + .get('/static/module-map.json'); expect(moduleMapResponse.statusCode).toBe(200); expect(moduleMapResponse.headers['content-type']).toMatch(/^application\/json/); expect( @@ -547,13 +546,13 @@ describe('one-app-dev-cdn', () => { expect(moduleResponse.body).toBe('console.log("a");'); expect(fetch.mock.calls).toEqual([ [ - 'https://example.com/module-map.json', + 'https://example.com/static/module-map.json', { agent: expect.any(ProxyAgent), }, ], [ - 'https://example.com//cdn/module-b/1.0.0/module-b.node.js', + 'https://example.com/cdn/module-b/1.0.0/module-b.node.js', { agent: expect.any(ProxyAgent), headers: { diff --git a/package-lock.json b/package-lock.json index 2cb58f43..4e8f6295 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,7 +75,6 @@ "yargs": "^17.5.1" }, "devDependencies": { - "@americanexpress/one-app-dev-cdn": "^3.3.2", "@americanexpress/one-app-dev-proxy": "^2.0.0", "@americanexpress/one-service-worker": "^1.0.4", "@babel/cli": "^7.19.3", @@ -533,49 +532,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/@americanexpress/one-app-dev-cdn": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@americanexpress/one-app-dev-cdn/-/one-app-dev-cdn-3.4.1.tgz", - "integrity": "sha512-0vg0ENCqZzlxIVArUIka1mDu3tSZ66CiaXeSwlnM4fZH5bjrL6hDuoFqeBxaGW56xFTHn5uiRNI1c1zhgfyr5g==", - "dev": true, - "dependencies": { - "chalk": "^3.0.0", - "compression": "^1.7.4", - "cors": "^2.8.4", - "got": "^11.8.3", - "ip": "^1.1.5", - "proxy-agent": "^5.0.0", - "rimraf": "^2.5.2" - }, - "peerDependencies": { - "express": "^4.0.0" - } - }, - "node_modules/@americanexpress/one-app-dev-cdn/node_modules/chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/@americanexpress/one-app-dev-cdn/node_modules/rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - } - }, "node_modules/@americanexpress/one-app-dev-proxy": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@americanexpress/one-app-dev-proxy/-/one-app-dev-proxy-2.0.0.tgz", @@ -9150,60 +9106,6 @@ "node": ">= 6" } }, - "node_modules/compressible": { - "version": "2.0.18", - "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", - "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==", - "dev": true, - "dependencies": { - "mime-db": ">= 1.43.0 < 2" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/compression": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz", - "integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==", - "dev": true, - "dependencies": { - "accepts": "~1.3.5", - "bytes": "3.0.0", - "compressible": "~2.0.16", - "debug": "2.6.9", - "on-headers": "~1.0.2", - "safe-buffer": "5.1.2", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/compression/node_modules/bytes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", - "integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/compression/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/compression/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -15903,6 +15805,25 @@ "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz", "integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==" }, + "node_modules/ip-address": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", + "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", + "dev": true, + "dependencies": { + "jsbn": "1.1.0", + "sprintf-js": "^1.1.3" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/ip-address/node_modules/sprintf-js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", + "dev": true + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -18376,6 +18297,12 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "dev": true + }, "node_modules/jsdom": { "version": "19.0.0", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-19.0.0.tgz", @@ -20545,15 +20472,6 @@ "node": ">= 0.8" } }, - "node_modules/on-headers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", - "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -24300,16 +24218,16 @@ } }, "node_modules/socks": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", - "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.3.tgz", + "integrity": "sha512-vfuYK48HXCTFD03G/1/zkIls3Ebr2YNa4qU9gHDZdblHLiqhJrJGkY3+0Nx0JpN9qBhJbVObc1CNciT1bIZJxw==", "dev": true, "dependencies": { - "ip": "^2.0.0", + "ip-address": "^9.0.5", "smart-buffer": "^4.2.0" }, "engines": { - "node": ">= 10.13.0", + "node": ">= 10.0.0", "npm": ">= 3.0.0" } }, @@ -24327,12 +24245,6 @@ "node": ">= 6" } }, - "node_modules/socks/node_modules/ip": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", - "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==", - "dev": true - }, "node_modules/sonic-boom": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.7.0.tgz", diff --git a/package.json b/package.json index b4565ea7..aff9cc95 100644 --- a/package.json +++ b/package.json @@ -144,7 +144,6 @@ "yargs": "^17.5.1" }, "devDependencies": { - "@americanexpress/one-app-dev-cdn": "^3.3.2", "@americanexpress/one-app-dev-proxy": "^2.0.0", "@americanexpress/one-service-worker": "^1.0.4", "@babel/cli": "^7.19.3", diff --git a/src/server/utils/devCdnFactory.js b/src/server/utils/devCdnFactory.js index a475bab2..5d0d259d 100644 --- a/src/server/utils/devCdnFactory.js +++ b/src/server/utils/devCdnFactory.js @@ -115,7 +115,7 @@ export const oneAppDevCdnFactory = ({ console.error('do not include one-app-dev-cdn in production'); } - const oneAppDevCdn = Fastify({ logger, disableRequestLogging: true }); + const oneAppDevCdn = Fastify({ logger, disableRequestLogging: false }); oneAppDevCdn.register(compress, { global: false, }); @@ -164,11 +164,11 @@ export const oneAppDevCdnFactory = ({ // eslint-disable-next-line consistent-return oneAppDevCdn.get('*', async (req, reply) => { const incomingRequestPath = req.url.replace('/static', ''); - if (matchPathToKnownRemoteModuleUrl(incomingRequestPath, remoteModuleBaseUrls)) { - const knownRemoteModuleBaseUrl = matchPathToKnownRemoteModuleUrl( - incomingRequestPath, - remoteModuleBaseUrls - ); + const knownRemoteModuleBaseUrl = matchPathToKnownRemoteModuleUrl( + incomingRequestPath, + remoteModuleBaseUrls + ); + if (knownRemoteModuleBaseUrl) { const remoteModuleBaseUrlOrigin = new URL(knownRemoteModuleBaseUrl).origin; if (cachedModuleFiles[incomingRequestPath]) { return reply @@ -176,7 +176,8 @@ export const oneAppDevCdnFactory = ({ .type('application/json') .send(cachedModuleFiles[incomingRequestPath]); } - const remoteModuleResponse = await fetch(`${remoteModuleBaseUrlOrigin}/${incomingRequestPath}`, { + + const remoteModuleResponse = await fetch(`${remoteModuleBaseUrlOrigin}${incomingRequestPath}`, { headers: { connection: 'keep-alive' }, agent: new ProxyAgent(), }); From eef53df93a3117b7ff11add2483279223047cf48 Mon Sep 17 00:00:00 2001 From: dpepin Date: Wed, 14 Feb 2024 12:31:22 -0500 Subject: [PATCH 2/2] fix(devCdn): re disable request loggin --- src/server/utils/devCdnFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/utils/devCdnFactory.js b/src/server/utils/devCdnFactory.js index 5d0d259d..c85bd129 100644 --- a/src/server/utils/devCdnFactory.js +++ b/src/server/utils/devCdnFactory.js @@ -115,7 +115,7 @@ export const oneAppDevCdnFactory = ({ console.error('do not include one-app-dev-cdn in production'); } - const oneAppDevCdn = Fastify({ logger, disableRequestLogging: false }); + const oneAppDevCdn = Fastify({ logger, disableRequestLogging: true }); oneAppDevCdn.register(compress, { global: false, });