Skip to content
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/loader/blazor/BootConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { BootJsonData } from "../../types/blazor";
import type { WebAssemblyBootResourceType } from "../../types";
import { loaderHelpers } from "../globals";

type LoadBootResourceCallback = (type: WebAssemblyBootResourceType, name: string, defaultUri: string, integrity: string) => string | Promise<Response> | null | undefined;
export type LoadBootResourceCallback = (type: WebAssemblyBootResourceType, name: string, defaultUri: string, integrity: string) => string | Promise<Response> | null | undefined;

export class BootConfigResult {
private constructor(public bootConfig: BootJsonData, public applicationEnvironment: string) {
Expand Down
43 changes: 40 additions & 3 deletions src/mono/wasm/runtime/loader/blazor/_Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { AssetBehaviours, AssetEntry, LoadingResource, WebAssemblyBootResou
import type { BootJsonData } from "../../types/blazor";

import { INTERNAL, loaderHelpers } from "../globals";
import { BootConfigResult } from "./BootConfig";
import { BootConfigResult, LoadBootResourceCallback } from "./BootConfig";
import { WebAssemblyResourceLoader } from "./WebAssemblyResourceLoader";
import { hasDebuggingEnabled } from "./_Polyfill";
import { ICUDataMode } from "../../types/blazor";
Expand All @@ -19,7 +19,7 @@ export async function loadBootConfig(config: MonoConfigInternal, module: DotnetM
const bootConfigPromise = BootConfigResult.initAsync(candidateOptions.loadBootResource, environment);
const bootConfigResult: BootConfigResult = await bootConfigPromise;
INTERNAL.resourceLoader = resourceLoader = await WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, candidateOptions || {});
mapBootConfigToMonoConfig(loaderHelpers.config, bootConfigResult.applicationEnvironment);
mapBootConfigToMonoConfig(loaderHelpers.config, bootConfigResult.applicationEnvironment, candidateOptions.loadBootResource);
setupModuleForBlazor(module);
}

Expand Down Expand Up @@ -73,7 +73,7 @@ export function setupModuleForBlazor(module: DotnetModuleInternal) {
module.disableDotnet6Compatibility = false;
}

export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, applicationEnvironment: string) {
export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, applicationEnvironment: string, customLoadBootResource?: LoadBootResourceCallback) {
const resources = resourceLoader.bootConfig.resources;

const assets: AssetEntry[] = [];
Expand Down Expand Up @@ -157,6 +157,43 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl
};
assets.push(asset);
}
for (let i = 0; i < resourceLoader.bootConfig.config.length; i++) {
let config = resourceLoader.bootConfig.config[i];
if (config === "appsettings.json" || config === `appsettings.${applicationEnvironment}.json`) {
const asset: AssetEntry = {
name: config,
resolvedUrl: `_framework/${name}`,
behavior: "vfs",
};

let response: Promise<Response> | null = null;
if (customLoadBootResource) {
const customLoadResult = customLoadBootResource("configuration", config, config, "");
if (customLoadResult instanceof Promise<Response>) {
// They are supplying an entire custom response, so just use that
response = customLoadResult;
} else if (typeof customLoadResult === "string") {
// They are supplying a custom URL, so use that with the default fetch behavior
config = customLoadResult;
}
}

if (!response) {
response = fetch(config, {
method: "GET",
credentials: "include",
cache: "no-cache",
});
}

asset.pendingDownload = {
name: config,
url: config,
response
};
assets.push(asset);
}
}

if (!hasIcuData) {
moduleConfig.globalizationMode = "invariant";
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/types/blazor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ export enum ICUDataMode {
All = 1,
Invariant = 2,
Custom = 3
}
}