[Blazor][Fixes #20935] Adds an Environment parameter to WebAssemblyStartOptions to provide or override the Environment value set by the host
This commit is contained in:
parent
4b943417a7
commit
472fc5058e
File diff suppressed because one or more lines are too long
|
|
@ -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
|
// Fetch the resources and prepare the Mono runtime
|
||||||
const bootConfigResult = await BootConfigResult.initAsync();
|
const bootConfigResult = await BootConfigResult.initAsync(environment);
|
||||||
|
|
||||||
const [resourceLoader] = await Promise.all([
|
const [resourceLoader] = await Promise.all([
|
||||||
WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, options || {}),
|
WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, options || {}),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ export class BootConfigResult {
|
||||||
private constructor(public bootConfig: BootJsonData, public applicationEnvironment: string) {
|
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', {
|
const bootConfigResponse = await fetch('_framework/blazor.boot.json', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
|
@ -10,8 +10,8 @@ export class BootConfigResult {
|
||||||
});
|
});
|
||||||
|
|
||||||
// While we can expect an ASP.NET Core hosted application to include the environment, other
|
// 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.
|
// hosts may not. Assume 'Production' in the absence of any specified value.
|
||||||
const applicationEnvironment = bootConfigResponse.headers.get('Blazor-Environment') || 'Production';
|
const applicationEnvironment = environment || bootConfigResponse.headers.get('Blazor-Environment') || 'Production';
|
||||||
const bootConfig: BootJsonData = await bootConfigResponse.json();
|
const bootConfig: BootJsonData = await bootConfigResponse.json();
|
||||||
|
|
||||||
return new BootConfigResult(bootConfig, applicationEnvironment);
|
return new BootConfigResult(bootConfig, applicationEnvironment);
|
||||||
|
|
|
||||||
|
|
@ -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.
|
* @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;
|
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.
|
// This type doesn't have to align with anything in BootConfig.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue