From 21b7e91e24284cf7baf6f9fa076b5d6f25d3e704 Mon Sep 17 00:00:00 2001 From: gimenes Date: Fri, 1 Sep 2023 10:23:28 -0300 Subject: [PATCH] re-use storeName --- shopify/loaders/proxy.ts | 19 +++++++------------ shopify/mod.ts | 5 ----- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/shopify/loaders/proxy.ts b/shopify/loaders/proxy.ts index ebe22011e..ed56aff07 100644 --- a/shopify/loaders/proxy.ts +++ b/shopify/loaders/proxy.ts @@ -14,22 +14,17 @@ const PATHS_TO_PROXY = [ const decoSiteMapUrl = "/sitemap/deco.xml"; const buildProxyRoutes = ( - { publicUrl, extraPaths, includeSiteMap, generateDecoSiteMap }: { - publicUrl?: string; + { storeName, extraPaths, includeSiteMap, generateDecoSiteMap }: { + storeName?: string; extraPaths: string[]; includeSiteMap?: string[]; generateDecoSiteMap?: boolean; }, ) => { - - if (!publicUrl) { - return []; - } + const publicUrl = new URL(`https://${storeName}.myshopify.com`); try { - const hostname = (new URL( - publicUrl?.startsWith("http") ? publicUrl : `https://${publicUrl}`, - )).hostname; + const hostname = publicUrl.hostname; // Rejects TLD mystore.com, keep this if Shopify doesn't support if (!hostname || hostname.split(".").length <= 2) { @@ -55,7 +50,7 @@ const buildProxyRoutes = ( routeFromPath, ); - const [include, routes] = generateDecoSiteMap + const [_include, routes] = generateDecoSiteMap ? [[...(includeSiteMap ?? []), decoSiteMapUrl], [{ pathTemplate: decoSiteMapUrl, handler: { @@ -65,7 +60,7 @@ const buildProxyRoutes = ( }, }]] : [includeSiteMap, []]; - + return [ ...routes, ...routesFromPaths, @@ -101,7 +96,7 @@ function loader( return buildProxyRoutes({ generateDecoSiteMap, includeSiteMap, - publicUrl: ctx.publicUrl, + storeName: ctx.storeName, extraPaths: extraPathsToProxy, }); } diff --git a/shopify/mod.ts b/shopify/mod.ts index 1bee2de72..8cb0b96c1 100644 --- a/shopify/mod.ts +++ b/shopify/mod.ts @@ -11,11 +11,6 @@ export interface Props { */ storeName: string; - /** - * @description Store public URL. - */ - publicUrl: string; - /** * @ttile Access Token * @description Shopify storefront access token.