dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.82k stars 458 forks source link

Add PathBaseMiddleware to Aspire Dashboard #4528

Open mu88 opened 4 months ago

mu88 commented 4 months ago

Hi πŸ‘‹πŸ»

Disclaimer: Since my issue is more a feature request than an API change, I decided not to use one of the predefined templates, but I'm happy to provide any further information you need.

I'm running the Aspire Dashboard as a standalone app via Docker which works nicely πŸ‘ŒπŸ» Since multiple Dockerized .NET apps are running on my host, I separated them by making use of the PathBaseMiddleware. This way, I can easily reroute them like this:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UsePathBase("/myapp");

Applying this pattern to the Aspire Dashboard would probably mean adding the following code to DashboardWebApplication.cs:

if (!string.IsNullOrEmpty(builder.Configuration[DashboardConfigNames.PathBase]))
{
    app.UsePathBase(builder.Configuration[DashboardConfigNames.PathBase]); // maybe sanitize PathBase here
}

This way, I could easily reroute the Aspire Dashboard and make it accessible on https://myhost/aspire-dashboard instead of using a dedicated port (e.g. https://myhost:18888/). A corresponding docker-compose.yml could look like this:

services:
  aspire-dashboard:
    image: mcr.microsoft.com/dotnet/aspire-dashboard
    container_name: aspire-dashboard
    ports:
      - 4317:18889
      - 18888:18888
    environment:
      - Dashboard__PathBase=/aspire-dashboard

However, I didn't do a comprehensive and all-encompassing review of the implications and whether this might break certain features - but at least I want to trigger a discussion πŸ™‚

mitchdenny commented 4 months ago

Do you have a reverse proxy in front?

mu88 commented 4 months ago

yes, nginx

mitchdenny commented 4 months ago

OK thanks for the additional context. @kvenkatrajan not sure where this sits for you in terms of prioritization. It's the first request I've seen for this.

kvenkatrajan commented 4 months ago

Thanks @mu88 ..Interesting proposal.

@WardenGnaw / @tmeschter any impact to how this gets launched in codespaces?

CC: @karolz-ms , @drewnoakes

fiotti commented 3 months ago

Duplicate of #4159

martin-gft commented 3 months ago

Upvoting this as well!