Paul Meems
Paul Meems

Reputation: 3294

Blazor WASM Azure Static Web App, Functions not working

I created a simple Blazor WASM webapp using C# .NET5. It connects to some Functions which in turn get some data from a SQL Server database. I followed the tutorial of BlazorTrain: https://www.youtube.com/watch?v=5QctDo9MWps

Locally using Azurite to emulate the Azure stuff it all works fine. But after deployment using GitHub Action the webapp starts but then it needs to get some data using the Functions and that fails. Running the Function in Postman results in a 503: Function host is not running.

I'm not sure what I need to configure more. I can't find the logging from Functions. I use the injected ILog, but can find the log messages in Azure Portal.
In Azure portal I see my 3 GET functions, but no option to test or see the logging.

Upvotes: 0

Views: 492

Answers (1)

Paul Meems
Paul Meems

Reputation: 3294

With the help of @Aravid I found my problem.
Because I locally needed to tell my client the URL of the API I added a configuration in Client\wwwroot\appsettings.Development.json.
Of course this file doesn't get deployed.

After changing my code in Program.cs to:

  var apiAddress = builder.Configuration["ApiAddress"] ?? $"{builder.HostEnvironment.BaseAddress}/api/";
  builder.Services.AddHttpClient("Api",(options) => {
                options.BaseAddress = new Uri(apiAddress);
            });

My client works again.

I also added my SqlServer connection string in the Application Settings of my Static Web App and the functions are working as well.

I hope somebody else will benefit from this. Took me several hours to figure it out ;)

Upvotes: 0

Related Questions