Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Discussion: How should we use service discovery in Blazor WASM? #582

Open
seesharprun opened this issue Jul 15, 2020 · 7 comments
Open

Discussion: How should we use service discovery in Blazor WASM? #582

seesharprun opened this issue Jul 15, 2020 · 7 comments

Comments

@seesharprun
Copy link

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.

@seesharprun
Copy link
Author

I put a stripped-down WIP Blazor app here: https://github.com/seesharprun/blazortye

@marinasundstrom
Copy link

marinasundstrom commented Jul 17, 2020

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.

@marinasundstrom
Copy link

I found this while browsing NuGet:

https://github.com/WildGums/Blorc.Tye

@jongio
Copy link

jongio commented Oct 25, 2020

It would be great to get official guidance from Microsoft on best approach here.

azsdke2e
azsdke2e2

@jkotalik
Copy link
Contributor

jkotalik commented Nov 5, 2020

@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.

@marinasundstrom
Copy link

marinasundstrom commented Nov 5, 2020

@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:

  1. Endpoint on the server-side with logic for exposing the configuration. If it is an hosted app then this would not be trivial. A package to install basically. Tye would handle the rest.
  2. Then a library for the client that fetches that data and exposes it through the Configuration API.
  3. In your standalone client-side app, you have to specify the endpoint in appconfig.json (or similar). This can be injected att development and even when you publish the app in containerized form.

@jongio
Copy link

jongio commented Nov 13, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants