Skip to content

Commit 29ed218

Browse files
authored
Merge pull request #6808 from Shopify/dlm-local-dev-testing
Rewrite dev store APIs in local dev for app preview
2 parents c990440 + ba17bbd commit 29ed218

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import {normalizeStoreFqdn} from '@shopify/cli-kit/node/context/fqdn'
1+
import {normalizeStoreFqdn, storeAdminUrl} from '@shopify/cli-kit/node/context/fqdn'
22

33
export function buildAppURLForWeb(storeFqdn: string, apiKey: string) {
44
const normalizedFQDN = normalizeStoreFqdn(storeFqdn)
5-
return `https://${normalizedFQDN}/admin/oauth/redirect_from_cli?client_id=${apiKey}`
5+
const adminUrl = storeAdminUrl(normalizedFQDN)
6+
return `https://${adminUrl}/admin/oauth/redirect_from_cli?client_id=${apiKey}`
67
}
78

89
export function buildAppURLForMobile(storeFqdn: string, apiKey: string) {
910
const normalizedFQDN = normalizeStoreFqdn(storeFqdn)
10-
const hostUrl = `${normalizedFQDN}/admin/apps/${apiKey}`
11+
const adminUrl = storeAdminUrl(normalizedFQDN)
12+
const hostUrl = `${adminUrl}/admin/apps/${apiKey}`
1113
const hostParam = Buffer.from(hostUrl).toString('base64').replace(/[=]/g, '')
1214
return `https://${hostUrl}?shop=${normalizedFQDN}&host=${hostParam}`
1315
}

packages/cli-kit/src/public/node/context/fqdn.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,20 @@ export function normalizeStoreFqdn(store: string): string {
139139
}
140140
const containDomain = (storeFqdn: string) =>
141141
storeFqdn.endsWith('.myshopify.com') || storeFqdn.endsWith('shopify.io') || storeFqdn.endsWith('.shop.dev')
142-
const normalizedFqdn = containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)
143-
// Use dev-api domain for OAuth redirects in local environment
144-
// See: https://github.com/Shopify/dev_server?tab=readme-ov-file#shop-redirects
145-
return normalizedFqdn.replace('.my.shop.dev', '.dev-api.shop.dev')
142+
return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)
143+
}
144+
145+
/**
146+
* Convert a store FQDN to the admin URL pattern for local development.
147+
* In local mode, transforms \{store\}.my.shop.dev to admin.shop.dev/store/\{store\}.
148+
*
149+
* @param storeFqdn - Normalized store FQDN.
150+
* @returns Store admin URL base (without protocol or path).
151+
*/
152+
export function storeAdminUrl(storeFqdn: string): string {
153+
if (serviceEnvironment() === 'local' && storeFqdn.endsWith('.my.shop.dev')) {
154+
const storeName = storeFqdn.replace('.my.shop.dev', '')
155+
return `admin.shop.dev/store/${storeName}`
156+
}
157+
return storeFqdn
146158
}

0 commit comments

Comments
 (0)