Browse Source

[Blazor][Fixes #20935] Adds an Environment parameter to WebAssemblyStartOptions to provide or override the Environment value set by the host

Michael Randers-Pehrson 5 years ago
parent
commit
472fc5058e

File diff suppressed because it is too large
+ 0 - 0
src/Components/Web.JS/dist/Release/blazor.webassembly.js


+ 4 - 1
src/Components/Web.JS/src/Boot.WebAssembly.ts

@@ -66,8 +66,11 @@ async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
     );
   });
 
+  // Get the custom environment setting if defined
+  const environment = options?.environment;
+
   // Fetch the resources and prepare the Mono runtime
-  const bootConfigResult = await BootConfigResult.initAsync();
+  const bootConfigResult = await BootConfigResult.initAsync(environment);
 
   const [resourceLoader] = await Promise.all([
     WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, options || {}),

+ 3 - 3
src/Components/Web.JS/src/Platform/BootConfig.ts

@@ -2,7 +2,7 @@ export class BootConfigResult {
   private constructor(public bootConfig: BootJsonData, public applicationEnvironment: string) {
   }
 
-  static async initAsync(): Promise<BootConfigResult> {
+  static async initAsync(environment?: string): Promise<BootConfigResult> {
     const bootConfigResponse = await fetch('_framework/blazor.boot.json', {
       method: 'GET',
       credentials: 'include',
@@ -10,8 +10,8 @@ export class BootConfigResult {
     });
 
     // While we can expect an ASP.NET Core hosted application to include the environment, other
-    // hosts may not. Assume 'Production' in the absenc of any specified value.
-    const applicationEnvironment = bootConfigResponse.headers.get('Blazor-Environment') || 'Production';
+    // hosts may not. Assume 'Production' in the absence of any specified value.
+    const applicationEnvironment = environment || bootConfigResponse.headers.get('Blazor-Environment') || 'Production';
     const bootConfig: BootJsonData = await bootConfigResponse.json();
 
     return new BootConfigResult(bootConfig, applicationEnvironment);

+ 5 - 0
src/Components/Web.JS/src/Platform/WebAssemblyStartOptions.ts

@@ -9,6 +9,11 @@ export interface WebAssemblyStartOptions {
    * @returns A URI string or a Response promise to override the loading process, or null/undefined to allow the default loading behavior.
    */
   loadBootResource(type: WebAssemblyBootResourceType, name: string, defaultUri: string, integrity: string) : string | Promise<Response> | null | undefined;
+
+  /**
+   * Override built-in environment setting on start.
+   */
+  environment?: string;
 }
 
 // This type doesn't have to align with anything in BootConfig.

Some files were not shown because too many files changed in this diff