Resolve saleor host/domain from full saleor api url (#2613)
This commit is contained in:
parent
231a32d115
commit
17e3c4c8f2
3 changed files with 11 additions and 14 deletions
|
@ -102,7 +102,7 @@ export const AppFrame: React.FC<Props> = ({
|
||||||
return (
|
return (
|
||||||
<iframe
|
<iframe
|
||||||
ref={frameRef}
|
ref={frameRef}
|
||||||
src={resolveAppIframeUrl(appId, src, shop.domain.host, params)}
|
src={resolveAppIframeUrl(appId, src, params)}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
onLoad={handleLoad}
|
onLoad={handleLoad}
|
||||||
className={clsx(classes.iframe, className)}
|
className={clsx(classes.iframe, className)}
|
||||||
|
|
|
@ -10,27 +10,22 @@ describe("resolveAppIframeUrl", () => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each<[string, string, string, Record<string, unknown>, string]>([
|
it.each<[string, string, Record<string, unknown>, string]>([
|
||||||
[
|
[
|
||||||
"XyZ123",
|
"XyZ123",
|
||||||
"https://my-app.vercel.app",
|
"https://my-app.vercel.app",
|
||||||
"shop.saleor.cloud",
|
|
||||||
{ param1: "param1" },
|
{ param1: "param1" },
|
||||||
"https://my-app.vercel.app?domain=shop.saleor.cloud&saleorApiUrl=https%3A%2F%2Fshop.saleor.cloud%2Fgraphql%2F&id=XyZ123¶m1=param1",
|
"https://my-app.vercel.app?domain=shop.saleor.cloud&saleorApiUrl=https%3A%2F%2Fshop.saleor.cloud%2Fgraphql%2F&id=XyZ123¶m1=param1",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"AbC987",
|
"AbC987",
|
||||||
"https://my-app.vercel.app/configuration",
|
"https://my-app.vercel.app/configuration",
|
||||||
"shop.saleor.cloud",
|
|
||||||
{ param1: "param1", param2: "param2" },
|
{ param1: "param1", param2: "param2" },
|
||||||
"https://my-app.vercel.app/configuration?domain=shop.saleor.cloud&saleorApiUrl=https%3A%2F%2Fshop.saleor.cloud%2Fgraphql%2F&id=AbC987¶m1=param1¶m2=param2",
|
"https://my-app.vercel.app/configuration?domain=shop.saleor.cloud&saleorApiUrl=https%3A%2F%2Fshop.saleor.cloud%2Fgraphql%2F&id=AbC987¶m1=param1¶m2=param2",
|
||||||
],
|
],
|
||||||
])(
|
])("Generates valid URL from segments", (id, appUrl, params, expectedUrl) => {
|
||||||
"Generates valid URL from segments",
|
const result = resolveAppIframeUrl(id, appUrl, params);
|
||||||
(id, appUrl, shopHostname, params, expectedUrl) => {
|
|
||||||
const result = resolveAppIframeUrl(id, appUrl, shopHostname, params);
|
|
||||||
|
|
||||||
expect(result).toEqual(expectedUrl);
|
expect(result).toEqual(expectedUrl);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -121,9 +121,11 @@ export const appsListUrl = (params?: AppListUrlQueryParams) =>
|
||||||
export const resolveAppIframeUrl = (
|
export const resolveAppIframeUrl = (
|
||||||
appId: string,
|
appId: string,
|
||||||
appUrl: string,
|
appUrl: string,
|
||||||
shopDomainHost: string,
|
|
||||||
params: AppDetailsUrlQueryParams,
|
params: AppDetailsUrlQueryParams,
|
||||||
) => {
|
) => {
|
||||||
|
const apiUrl = getApiUrl();
|
||||||
|
const apiUrlHost = new URL(getApiUrl()).hostname;
|
||||||
|
|
||||||
const iframeContextQueryString = `?${stringifyQs(
|
const iframeContextQueryString = `?${stringifyQs(
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -133,8 +135,8 @@ export const resolveAppIframeUrl = (
|
||||||
* Difference will be:
|
* Difference will be:
|
||||||
* shop.saleor.cloud -> https://shop.saleor.cloud/graphql/
|
* shop.saleor.cloud -> https://shop.saleor.cloud/graphql/
|
||||||
*/
|
*/
|
||||||
domain: shopDomainHost,
|
domain: apiUrlHost,
|
||||||
saleorApiUrl: getApiUrl(),
|
saleorApiUrl: apiUrl,
|
||||||
id: appId,
|
id: appId,
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue