Separately deployed blazor client and server. How do I make sure they can communicate with each other

Viewed 37

Edit: The repository I am deploying is located here: https://github.com/sculleywr1/MermaidCraftsFE

I am using the CI/CD pipeline provided by Github and Azure through the Visual Studio 2022 IDE.

I have successfully configured the Base Address in my Client app to point to the proper address. Started getting the expected CORS errors that the 'Access-Control-Allow-Origin' header was missing. So I configured a Header Delegating Handle like so:

public class HeaderDelegatingHandler : DelegatingHandler
    {
        public HeaderDelegatingHandler() : base(new HttpClientHandler())
            { }

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            request.Headers.Add("Access-Control-Allow-Origin", "*");

            return base.SendAsync(request, cancellationToken);
        }
    }

I also edited the Cors Policy in Program.cs in the server like so:

var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCors(options =>
{
    options.AddPolicy(name: MyAllowSpecificOrigins,
        policy =>
        {
            policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
        });
});

Azure deployed the Web Api as an API Management Service here: https://mermaidcraftsfeserverapi.azure-api.net

I am attempting to deploy a Blazor WebAssembly App to Azure through VS2022 and it's making me use two separate instances for the client and the server. I have successfully configured my CI/CD pipeline so that they will both update whenever I push to GitHub, and even gotten them to successfully build.

I have created production and development profiles in Spring with Java, but haven't done that in DotNet 6. I have the server deployed to https://mermaidcraftsfeserverapi.azure-api.net, and the client deployed to https://mermaidcrafts.azurewebsites.net.

Where do I go to configure how the client connects and, if necessary, how the server will recognize the client's address (I'm assuming there's a possibility of CORS issues in this deployment)? And how would I alter the files necessary?

I have done away with the Shared part of the program to simplify the deployment process, so they are all calling on the models in their own separate Models folders. So I will not need to wire that into them.

0 Answers
Related