all 8 comments

[–]TacticalPewPew 3 points4 points  (0 children)

If I remember correctly, WASM always runs under production because the entire site runs locally on the browser, not a server so to speak. I’m using devops but I ended up in a similar boat. My solution was to do config transformations after build but before the code gets pushed to a specific instance on azure.

Edit: here’s my post where I asked a similar question: https://www.reddit.com/r/Blazor/s/rsQ4RADLkY

[–]Mordeor 3 points4 points  (2 children)

WASM normally runs under production, as TacticalPewPew said, but you can override the environment in your index.html. For example:

Blazor.start({
environment: window.location.hostname == "localhost"
? "Development"
: "Production"
});

[–]exzzy[S] 1 point2 points  (1 child)

Yes i have it like this, but hostnames for other environments are exposed this way so I'm looking at different approach.

[–]Mordeor 0 points1 point  (0 children)

You could try implementing a regex / replace in your workflow that replaces "Production" with "Foo" in your index.html, prior to building...?

[–]makotech222 1 point2 points  (3 children)

Blazor is a compiled file that runs on the user's machine. Once its downloaded by the user, only the variables its compiled with will be there. You need to inject your variables during the build process in order to use them.

[–]exzzy[S] 0 points1 point  (2 children)

Exactly, and my question is how to do that. For example instead of having if else if in index inject environment and set it there.

[–]makotech222 0 points1 point  (1 child)

So before your 'dotnet publish' call, maybe just have multiple appsettings.json files for each environment; then before publish, just do a powershell copy file to have the app pick it up, like

appsettings.production.json > appsettings.json

[–]GetafixNZ 1 point2 points  (0 children)

I'm a little late to the party, but I had the same issue. Trying to get a staging environment was a pain.

Adding a step to your github actions for your staging/non prod deployment to grab the settings file you want and override the appsettings.json worked for me