Skip to content

Commit 25ae8a4

Browse files
update
1 parent aee5fca commit 25ae8a4

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

src/load.ts

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,47 +83,16 @@ export async function load(
8383
* @param endpoint The URL to the CDN.
8484
* @param options Optional parameters.
8585
*/
86-
export async function loadCdn(endpoint: URL | string, options?: AzureAppConfigurationOptions): Promise<AzureAppConfiguration>;
86+
export async function loadFromCdn(endpoint: URL | string, options?: AzureAppConfigurationOptions): Promise<AzureAppConfiguration>;
8787

88-
export async function loadCdn(
88+
export async function loadFromCdn(
8989
endpoint: string | URL,
9090
appConfigOptions?: AzureAppConfigurationOptions
9191
): Promise<AzureAppConfiguration> {
92-
const startTimestamp = Date.now();
93-
if (typeof endpoint === "string") {
94-
try {
95-
endpoint = new URL(endpoint);
96-
} catch (error) {
97-
if (error.code === "ERR_INVALID_URL") {
98-
throw new Error("Invalid endpoint URL.", { cause: error });
99-
} else {
100-
throw error;
101-
}
102-
}
103-
}
10492
const emptyTokenCredential: TokenCredential = {
10593
getToken: async () => ({ token: "", expiresOnTimestamp: 0 })
10694
};
107-
const options = appConfigOptions;
108-
const clientOptions = getClientOptions(options);
109-
// App Configuration SDK will not distinguish between CDN and App Configuration endpoints. The SDK will just send request to the endpoint with the given token credential.
110-
// CDN should be the front door of App Configuration and forward the request to the App Configuration service.
111-
const client = new AppConfigurationClient(endpoint.toString(), emptyTokenCredential, clientOptions);
112-
113-
try {
114-
const appConfiguration = new AzureAppConfigurationImpl(client, options);
115-
await appConfiguration.load();
116-
return appConfiguration;
117-
} catch (error) {
118-
// load() method is called in the application's startup code path.
119-
// Unhandled exceptions cause application crash which can result in crash loops as orchestrators attempt to restart the application.
120-
// Knowing the intended usage of the provider in startup code path, we mitigate back-to-back crash loops from overloading the server with requests by waiting a minimum time to propagate fatal errors.
121-
const delay = MIN_DELAY_FOR_UNHANDLED_ERROR - (Date.now() - startTimestamp);
122-
if (delay > 0) {
123-
await new Promise((resolve) => setTimeout(resolve, delay));
124-
}
125-
throw error;
126-
}
95+
return await load(endpoint, emptyTokenCredential, appConfigOptions);
12796
}
12897

12998
function instanceOfTokenCredential(obj: unknown) {

0 commit comments

Comments
 (0)