From 1b2de098cc26affbb4479a7372aac78476d50468 Mon Sep 17 00:00:00 2001 From: Devis Lucato Date: Fri, 13 Dec 2024 08:12:50 -0800 Subject: [PATCH] When using Aspire locally always use the same port, without proxying (#287) Aspire by default randomizes ports, however this means that cookies from a previous session most likely don't work, in which case the workbench show the set of initial banners and asks to sign in, every time. The PR changes this behavior on localhost, to always use port 4000 (assuming it's free), similarly to how the app runs without Aspire. --- aspire-orchestrator/Aspire.AppHost/Program.cs | 3 ++- aspire-orchestrator/Aspire.AppHost/appsettings.json | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aspire-orchestrator/Aspire.AppHost/Program.cs b/aspire-orchestrator/Aspire.AppHost/Program.cs index f7a8cae3..4156dc2d 100644 --- a/aspire-orchestrator/Aspire.AppHost/Program.cs +++ b/aspire-orchestrator/Aspire.AppHost/Program.cs @@ -68,7 +68,8 @@ private static IDistributedApplicationBuilder AddSemanticWorkbench(this IDistrib // When running locally if (!builder.ExecutionContext.IsPublishMode) { - workbenchApp.WithHttpsEndpoint(env: "PORT"); + if (!int.TryParse(builder.Configuration["Workbench:AppPort"], out var appPort)) { appPort = 4000; } + workbenchApp.WithHttpsEndpoint(port: appPort, env: "PORT", isProxied: false); } return builder; diff --git a/aspire-orchestrator/Aspire.AppHost/appsettings.json b/aspire-orchestrator/Aspire.AppHost/appsettings.json index 71a9a93d..8cd85a71 100644 --- a/aspire-orchestrator/Aspire.AppHost/appsettings.json +++ b/aspire-orchestrator/Aspire.AppHost/appsettings.json @@ -6,8 +6,14 @@ "Aspire.Hosting.Dcp": "Warning" } }, + "Workbench": { + // Used only when running Aspire locally, ie not in the cloud + // Port 4000 is the default port used also when not using Aspire. + // Using the same port allows to keep cookies and other local settings. + "AppPort": 4000 + }, "EntraID": { - "ClientId": "22cb77c3-ca98-4a26-b4db-ac4dcecba690", - "Authority": "https://login.microsoftonline.com/common" + "Authority": "https://login.microsoftonline.com/common", + "ClientId": "22cb77c3-ca98-4a26-b4db-ac4dcecba690" } }