Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-161280: Update setLibs so it points to .adobe.com/libs #115

Merged
merged 1 commit into from
Nov 5, 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
14 changes: 9 additions & 5 deletions edsdme/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ export const [setLibs, getLibs] = (() => {
return [
(prodLibs, location) => {
libs = (() => {
const { hostname, search } = location || window.location;
// TODO: check if better ways are possible for partners.stage.adobe.com
if (!(hostname.includes('.hlx.') || hostname.includes('local') || hostname === 'partners.stage.adobe.com' || hostname === 'partners.adobe.com')) return prodLibs;
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'local') return 'http://localhost:6456/libs';
const { hostname, search, origin } = location || window.location;
if (origin.endsWith('adobe.com')) {
return origin.replace('partners', 'milo') + prodLibs;
}
const partnerBranch = hostname.startsWith('main') ? 'main' : 'stage';
const branch = new URLSearchParams(search).get('milolibs') || partnerBranch;
if (branch === 'local') {
return 'http://localhost:6456/libs';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why port 6456? never seen this port before

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ben-Zahler this is the default milo port for when you want to get milo code from your machine so you can debug it. Milo repo has command npm run libs, this will spin up server on port 6456 and when you set query param milolibs=local in your url, you fetch milo code from that server and any local changes that you make to milo repo will be reflected on your page.

}
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
})();
return libs;
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/utils.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Test utils.js', () => {
it('Milo libs', () => {
window.location.hostname = 'partners.stage.adobe.com';
const libs = setLibs('/libs');
expect(libs).toEqual('https://main--milo--adobecom.hlx.live/libs');
expect(libs).toEqual('https://milo.stage.adobe.com/libs');
});
describe('Test update footer and gnav', () => {
beforeEach(() => {
Expand Down
25 changes: 23 additions & 2 deletions test/scripts/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,40 @@ import { setLibs } from '../../edsdme/scripts/utils.js';
describe('Libs', () => {
it('Default Libs', () => {
const libs = setLibs('/libs');
expect(libs).to.equal('https://stage--milo--adobecom.hlx.live/libs');
});
it('Main Libs', () => {
const location = {
hostname: 'main--dme-partners.hlx.page',
origin: 'https://main--dme-partners.hlx.page',
};
const libs = setLibs('/libs', location);
expect(libs).to.equal('https://main--milo--adobecom.hlx.live/libs');
});
it('Returns prod milo for prod', () => {
const location = { origin: 'https://partners.adobe.com' };
const libs = setLibs('/libs', location);
expect(libs).to.equal('https://milo.adobe.com/libs');
});
it('Returns stage milo for stage', () => {
const location = { origin: 'https://partners.stage.adobe.com' };
const libs = setLibs('/libs', location);
expect(libs).to.equal('https://milo.stage.adobe.com/libs');
});

it('Does not support milolibs query param on prod', () => {
const location = {
hostname: 'business.adobe.com',
origin: 'https://partners.adobe.com',
search: '?milolibs=foo',
};
const libs = setLibs('/libs', location);
expect(libs).to.equal('/libs');
expect(libs).to.equal('https://milo.adobe.com/libs');
});

it('Supports milolibs query param', () => {
const location = {
hostname: 'localhost',
origin: 'http://localhost:3000',
search: '?milolibs=foo',
};
const libs = setLibs('/libs', location);
Expand All @@ -28,6 +47,7 @@ describe('Libs', () => {
it('Supports local milolibs query param', () => {
const location = {
hostname: 'localhost',
origin: 'http://localhost:3000',
search: '?milolibs=local',
};
const libs = setLibs('/libs', location);
Expand All @@ -37,6 +57,7 @@ describe('Libs', () => {
it('Supports forked milolibs query param', () => {
const location = {
hostname: 'localhost',
origin: 'http://localhost:3000',
search: '?milolibs=awesome--milo--forkedowner',
};
const libs = setLibs('/libs', location);
Expand Down
Loading