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 (
|
||||
<iframe
|
||||
ref={frameRef}
|
||||
src={resolveAppIframeUrl(appId, src, shop.domain.host, params)}
|
||||
src={resolveAppIframeUrl(appId, src, params)}
|
||||
onError={onError}
|
||||
onLoad={handleLoad}
|
||||
className={clsx(classes.iframe, className)}
|
||||
|
|
|
@ -10,27 +10,22 @@ describe("resolveAppIframeUrl", () => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it.each<[string, string, string, Record<string, unknown>, string]>([
|
||||
it.each<[string, string, Record<string, unknown>, string]>([
|
||||
[
|
||||
"XyZ123",
|
||||
"https://my-app.vercel.app",
|
||||
"shop.saleor.cloud",
|
||||
{ param1: "param1" },
|
||||
"https://my-app.vercel.app?domain=shop.saleor.cloud&saleorApiUrl=https%3A%2F%2Fshop.saleor.cloud%2Fgraphql%2F&id=XyZ123¶m1=param1",
|
||||
],
|
||||
[
|
||||
"AbC987",
|
||||
"https://my-app.vercel.app/configuration",
|
||||
"shop.saleor.cloud",
|
||||
{ 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",
|
||||
],
|
||||
])(
|
||||
"Generates valid URL from segments",
|
||||
(id, appUrl, shopHostname, params, expectedUrl) => {
|
||||
const result = resolveAppIframeUrl(id, appUrl, shopHostname, params);
|
||||
])("Generates valid URL from segments", (id, appUrl, params, expectedUrl) => {
|
||||
const result = resolveAppIframeUrl(id, appUrl, params);
|
||||
|
||||
expect(result).toEqual(expectedUrl);
|
||||
},
|
||||
);
|
||||
expect(result).toEqual(expectedUrl);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -121,9 +121,11 @@ export const appsListUrl = (params?: AppListUrlQueryParams) =>
|
|||
export const resolveAppIframeUrl = (
|
||||
appId: string,
|
||||
appUrl: string,
|
||||
shopDomainHost: string,
|
||||
params: AppDetailsUrlQueryParams,
|
||||
) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const apiUrlHost = new URL(getApiUrl()).hostname;
|
||||
|
||||
const iframeContextQueryString = `?${stringifyQs(
|
||||
{
|
||||
/**
|
||||
|
@ -133,8 +135,8 @@ export const resolveAppIframeUrl = (
|
|||
* Difference will be:
|
||||
* shop.saleor.cloud -> https://shop.saleor.cloud/graphql/
|
||||
*/
|
||||
domain: shopDomainHost,
|
||||
saleorApiUrl: getApiUrl(),
|
||||
domain: apiUrlHost,
|
||||
saleorApiUrl: apiUrl,
|
||||
id: appId,
|
||||
...params,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue