Open seesharprun opened 4 years ago
I put a stripped-down WIP Blazor app here: https://github.com/seesharprun/blazortye
Client-side apps are different due to being executed on the client. I think that you either have to request it from the orchestrator somehow or inject it at build time.
Ideally, there would be an API endpoint which the client-side app would request configuration from. Tye could provide that endpoint.
I found this while browsing NuGet:
It would be great to get official guidance from Microsoft on best approach here.
azsdke2e azsdke2e2
@robertsundstrom hit the nail on the head here; either we need to inject it at build time, which requires knowing about a publicly exposed ingress endpoint, or setup a service/api.
I'm not sure which solution is better here though.
@jkotalik Excuse me for repeating myself:
Just ask yourself: What would the Azure Team come up with. So that is why I believe that they would server the configuration just like you would a appsettings.json
through some endpoint. I don't know what is best when it comes to security though. These are public endpoints anyway and Blazor webassembly apps should not expose any secrets, like API keys and connection strings. That should be on the server-side.
The cases might differ when you run standalone Blazor or hosted Blazor (or any other app type).
I would probably implement it like this:
appconfig.json
(or similar). This can be injected att development and even when you publish the app in containerized form.I ended up using ingress for this:
So in my blazor app, I just need to bind to the same host that the blazor app is bound to. B/c of ingress it appears to be the same host to the blazor app.
- name: ingress
rules:
- path: /
service: memealyzernetwebapp
- path: /images
service: memealyzernetapi
preservePath: true
- path: /image
service: memealyzernetapi
preservePath: true
- path: /config
service: memealyzernetapi
preservePath: true
- path: /imagehub
service: memealyzernetapi
preservePath: true
tags:
- staging
- prod
I was building out a sample that I wanted to contribute via PR. The sample would have a Blazor WASM frontend and a simple Web API backend.
As with the angular sample, I was forced to hard-code the ports so I could know how to call the API on the back-end. The Blazor WASM project runs client-side, so it wouldn't have access to the server-side configuration settings unless I hosted it in an ASP.NET Core project complicating the sample.
I know hard-coding for client-side apps is the reality now, but is there any plans to ease this minor pain? I saw some issues mention generating constants use a source generator, but that didn't seem to be in progress.
BTW: The
GetServiceUri
extension method works well server-side and that was a great addition.