Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

fix(devCdn): removing extra / which created malformed url #1295

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions __tests__/server/utils/devCdnFactory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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: {
Expand Down
148 changes: 30 additions & 118 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions src/server/utils/devCdnFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,20 @@ 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
.code(200)
.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(),
});
Expand Down
Loading