-
Notifications
You must be signed in to change notification settings - Fork 4
New API to load from CDN endpoint #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5135f8e
f9984f1
48dca22
aee5fca
234ab73
db8b023
5aae5ea
a7124d8
c8c366d
263859d
e4421ec
084825d
cec0605
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,54 @@ export async function load( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Loads the data from a CDN and returns an instance of AzureAppConfiguration. | ||
| * @param endpoint The URL to the CDN. | ||
| * @param options Optional parameters. | ||
| */ | ||
| export async function loadCdn(endpoint: URL | string, options?: AzureAppConfigurationOptions): Promise<AzureAppConfiguration>; | ||
|
|
||
| export async function loadCdn( | ||
| endpoint: string | URL, | ||
|
||
| appConfigOptions?: AzureAppConfigurationOptions | ||
| ): Promise<AzureAppConfiguration> { | ||
| const startTimestamp = Date.now(); | ||
| if (typeof endpoint === "string") { | ||
| try { | ||
| endpoint = new URL(endpoint); | ||
| } catch (error) { | ||
| if (error.code === "ERR_INVALID_URL") { | ||
| throw new Error("Invalid endpoint URL.", { cause: error }); | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
| const emptyTokenCredential: TokenCredential = { | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getToken: async () => ({ token: "", expiresOnTimestamp: 0 }) | ||
avanigupta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| const options = appConfigOptions; | ||
| const clientOptions = getClientOptions(options); | ||
| // 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. | ||
| // CDN should be the front door of App Configuration and forward the request to the App Configuration service. | ||
| const client = new AppConfigurationClient(endpoint.toString(), emptyTokenCredential, clientOptions); | ||
|
|
||
| try { | ||
| const appConfiguration = new AzureAppConfigurationImpl(client, options); | ||
| await appConfiguration.load(); | ||
| return appConfiguration; | ||
| } catch (error) { | ||
| // load() method is called in the application's startup code path. | ||
| // Unhandled exceptions cause application crash which can result in crash loops as orchestrators attempt to restart the application. | ||
| // 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. | ||
| const delay = MIN_DELAY_FOR_UNHANDLED_ERROR - (Date.now() - startTimestamp); | ||
| if (delay > 0) { | ||
| await new Promise((resolve) => setTimeout(resolve, delay)); | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| function instanceOfTokenCredential(obj: unknown) { | ||
| return obj && typeof obj === "object" && "getToken" in obj && typeof obj.getToken === "function"; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it makes more sense to name it
loadFromCDNinsead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will use camelCase, so it will be
loadFromCdn