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-137401] Pathfinder origin fix #2464

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions libs/blocks/path-finder/path-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getReqOptions } from '../../tools/sharepoint/msal.js';
import { createTag } from '../../utils/utils.js';

const SCOPES = ['files.readwrite', 'sites.readwrite.all'];
const TELEMETRY = { application: { appName: 'Milo - Where am I' } };
const TELEMETRY = { application: { appName: 'Milo - Path Finder' } };

const getSharePointDetails = (() => {
let site;
Expand All @@ -16,7 +16,7 @@ const getSharePointDetails = (() => {
if (site && driveId && reqOpts) return { site, driveId, reqOpts };

// Fetching SharePoint details
const { sharepoint } = await getServiceConfig(origin);
const { sharepoint } = await getServiceConfig();
({ site } = sharepoint);
driveId = sharepoint.driveId ? `drives/${sharepoint.driveId}` : 'drive';
reqOpts = getReqOptions();
Expand Down
2 changes: 1 addition & 1 deletion libs/tools/sharepoint/msal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getMSALConfig(telemetry) {
const { base } = getConfig();
await loadScript(`${base}/deps/msal-browser-2.34.0.js`);

const { sharepoint } = await getServiceConfig(window.location.origin);
const { sharepoint } = await getServiceConfig();

const auth = {
clientId: sharepoint.clientId,
Expand Down
10 changes: 9 additions & 1 deletion libs/utils/service-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@

let config;

function getSiteOrigin() {
const search = new URLSearchParams(window.location.search);
const repo = search.get('repo');
const owner = search.get('owner');
return repo && owner ? `https://main--${repo}--${owner}.hlx.live` : window.location.origin;
}

Check warning on line 16 in libs/utils/service-config.js

View check run for this annotation

Codecov / codecov/patch

libs/utils/service-config.js#L11-L16

Added lines #L11 - L16 were not covered by tests

/**
* Get Service Config
* @param {*} origin The origin of the site to pull the config from.
* @param {*} envName The name of the environment to pull configs for.
* @returns the config
*/
export default async function getServiceConfig(origin, envName) {
export default async function getServiceConfig(suppliedOrigin, envName) {
if (config) return config;
const origin = suppliedOrigin || getSiteOrigin();
const utilsConfig = getConfig();
const queryEnv = new URLSearchParams(window.location.search).get('env');
const env = queryEnv || envName || utilsConfig.env.name;
Expand Down
Loading