Skip to content

Commit 185d95e

Browse files
Merge pull request #6099 from Shopify/fix-app-proxy-caching
Always regenerate ApplicationURLs during dev
2 parents 846c1eb + e36ca5c commit 185d95e

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/app/src/cli/models/app/loader.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ wrong = "property"
23422342
await expect(loadTestingApp()).rejects.toThrow()
23432343
})
23442344

2345-
test('preserves values from the previous app when reloading', async () => {
2345+
test('regenerates devApplicationURLs when reloading', async () => {
23462346
// Given
23472347
const appConfiguration = `
23482348
name = "my-app"
@@ -2355,6 +2355,11 @@ wrong = "property"
23552355
23562356
[auth]
23572357
redirect_urls = ["https://example.com/auth"]
2358+
2359+
[app_proxy]
2360+
url = "https://example.com"
2361+
subpath = "updated"
2362+
prefix = "new"
23582363
`
23592364
await writeConfig(appConfiguration)
23602365

@@ -2381,11 +2386,16 @@ wrong = "property"
23812386
userProvidedConfigName: undefined,
23822387
})) as AppLinkedInterface
23832388

2384-
// Set some values that should be preserved
2389+
// Set some values that should be regenerated
23852390
const customDevUUID = 'custom-dev-uuid'
23862391
const customAppURLs = {
23872392
applicationUrl: 'http://custom.dev',
23882393
redirectUrlWhitelist: ['http://custom.dev/auth'],
2394+
appProxy: {
2395+
proxyUrl: 'https://example.com',
2396+
proxySubPath: 'initial',
2397+
proxySubPathPrefix: 'old',
2398+
},
23892399
}
23902400
app.allExtensions[0]!.devUUID = customDevUUID
23912401
app.setDevApplicationURLs(customAppURLs)
@@ -2395,7 +2405,19 @@ wrong = "property"
23952405

23962406
// Then
23972407
expect(reloadedApp.allExtensions[0]?.devUUID).toBe(customDevUUID)
2398-
expect(reloadedApp.devApplicationURLs).toEqual(customAppURLs)
2408+
expect(reloadedApp.devApplicationURLs).toEqual({
2409+
applicationUrl: 'http://custom.dev',
2410+
redirectUrlWhitelist: [
2411+
'http://custom.dev/auth/callback',
2412+
'http://custom.dev/auth/shopify/callback',
2413+
'http://custom.dev/api/auth/callback',
2414+
],
2415+
appProxy: {
2416+
proxyUrl: 'https://custom.dev',
2417+
proxySubPath: 'updated',
2418+
proxySubPathPrefix: 'new',
2419+
},
2420+
})
23992421
expect(reloadedApp.name).toBe(app.name)
24002422
expect(reloadedApp.packageManager).toBe(app.packageManager)
24012423
expect(reloadedApp.nodeDependencies).toEqual(app.nodeDependencies)

packages/app/src/cli/models/app/loader.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {loadLocalExtensionsSpecifications} from '../extensions/load-specificatio
3434
import {UIExtensionSchemaType} from '../extensions/specifications/ui_extension.js'
3535
import {patchAppHiddenConfigFile} from '../../services/app/patch-app-configuration-file.js'
3636
import {getOrCreateAppConfigHiddenPath} from '../../utilities/app/config/hidden-app-config.js'
37+
import {ApplicationURLs, generateApplicationURLs} from '../../services/dev/urls.js'
3738
import {showMultipleCLIWarningIfNeeded} from '@shopify/cli-kit/node/multiple-installation-warning'
3839
import {fileExists, readFile, glob, findPathUp, fileExistsSync} from '@shopify/cli-kit/node/fs'
3940
import {zod} from '@shopify/cli-kit/node/schema'
@@ -389,7 +390,7 @@ class AppLoader<TConfig extends AppConfiguration, TModuleSpec extends ExtensionS
389390
configSchema,
390391
remoteFlags: this.remoteFlags,
391392
hiddenConfig,
392-
devApplicationURLs: this.previousApp?.devApplicationURLs,
393+
devApplicationURLs: this.getDevApplicationURLs(configuration, webs),
393394
})
394395

395396
// Show CLI notifications that are targetted for when your app has specific extension types
@@ -788,6 +789,17 @@ class AppLoader<TConfig extends AppConfiguration, TModuleSpec extends ExtensionS
788789
})
789790
})
790791
}
792+
793+
private getDevApplicationURLs(currentConfiguration: TConfig, webs: Web[]): ApplicationURLs | undefined {
794+
const previousDevUrls = this.previousApp?.devApplicationURLs
795+
if (!previousDevUrls || !isCurrentAppSchema(currentConfiguration)) return previousDevUrls
796+
797+
return generateApplicationURLs(
798+
previousDevUrls.applicationUrl,
799+
webs.map(({configuration}) => configuration.auth_callback_path).find((path) => path),
800+
currentConfiguration.app_proxy,
801+
)
802+
}
791803
}
792804

793805
/**

0 commit comments

Comments
 (0)