Centralize SignalR hub URL config via BaseUrl property

Refactored hub URL handling to use a single BaseUrl property in FruitBankConstClient, set at startup from appsettings ("AyCode:Urls:BaseUrl"). Removed hardcoded and commented-out URLs. All startup files now hydrate BaseUrl and construct hub URLs at runtime, ensuring both fbHub and loggerHub use the same base. The AcHubConnection:Url setting is now ignored in appsettings.json. Added fast-fail if BaseUrl is missing. Also updated PowerShell build/test commands in settings.local.json. This prevents environment mismatches and enforces explicit configuration.
This commit is contained in:
Loretta 2026-07-13 07:01:42 +02:00
parent a3604d7333
commit d1217700b4
8 changed files with 52 additions and 22 deletions

File diff suppressed because one or more lines are too long

View File

@ -7,18 +7,20 @@ public static class FruitBankConstClient
{
public static string DefaultLocale = "en-US";
//public static string BaseUrl = "https://localhost:59579"; //FrutiBank nop
//public static string BaseUrl = "https://localhost:44372"; //FrutiBank nop
public static string BaseUrl = "https://shop.fruitbank.hu"; //FrutiBank nop
//public static string BaseUrl = "https://fruitbank.mangoweb.hu"; //FrutiBank nop test
#if RELEASE
//public static string BaseUrl = "https://shop.fruitbank.hu"; //FrutiBank nop
#endif
//public static string BaseUrl = "http://localhost:59579"; //FrutiBank nop
//public static string BaseUrl = "http://10.0.2.2:59579"; //FrutiBank (android) nop
//public static string BaseUrl = "https://localhost:7144"; //HybridApp
// A nop szerver base URL-je. Induláskor a host tölti fel az appsettings "AyCode:Urls:BaseUrl"-ből
// (ld. Program.cs / MauiProgram.cs). Az fbHub ÉS a loggerHub is EBBŐL az egy értékből származik (+/fbHub, +/loggerHub).
// Default: null — ha nincs beállítva, az OLVASÁS exception-t dob, nem megy tovább csendben hiányzó/rossz URL-lel.
// A környezet-váltás az appsettings-ben történik:
// dev: https://localhost:59579 | prod: https://shop.fruitbank.hu | test: https://fruitbank.mangoweb.hu | android: http://10.0.2.2:59579
private static string? _baseUrl;
public static string BaseUrl
{
get => !string.IsNullOrWhiteSpace(_baseUrl)
? _baseUrl
: throw new InvalidOperationException("FruitBankConstClient.BaseUrl nincs beállítva — a host indulásakor hidratáld az appsettings 'AyCode:Urls:BaseUrl' értékéből (Program.cs / MauiProgram.cs).");
set => _baseUrl = value;
}
public static string DefaultHubName = "fbHub";
public static string LoggerHubName = "loggerHub";

View File

@ -26,8 +26,7 @@
},
"AcHubConnection": {
"Url": "https://localhost:59579/fbHub",
//"Url": "https://shop.fruitbank.hu/fbHub",
// Az Url innen KIVÉVE: az fbHub és a loggerHub is az AyCode:Urls:BaseUrl-ből származik (kódban: +/fbHub, +/loggerHub).
"TransportMaxBufferSize": 30000000,
"ApplicationMaxBufferSize": 30000000,
"CloseTimeout": "00:00:10",

View File

@ -18,6 +18,11 @@ using Microsoft.Extensions.Options;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// Hub-URL-ek EGY forrásból: az fbHub és a loggerHub is az AyCode:Urls:BaseUrl-ből származik.
// A loggerHub writer a FruitBankConstClient.BaseUrl-t olvassa, ezért induláskor onnan hidratáljuk.
FruitBankConstClient.BaseUrl = builder.Configuration["AyCode:Urls:BaseUrl"]
?? throw new InvalidOperationException("Hiányzik az 'AyCode:Urls:BaseUrl' az appsettings-ből — a hub-ok URL-je ebből származik.");
builder.Services.AddDevExpressBlazor(configure => configure.SizeMode = DevExpress.Blazor.SizeMode.Medium);
// Add device-specific services used by the FruitBankHybrid.Shared project
@ -32,7 +37,12 @@ builder.Services.AddSingleton<LoggedInModel>(sp => new LoggedInModel(sp.GetRequi
// Bind SignalR options from wwwroot/appsettings.json (loaded automatically by WebAssemblyHostBuilder) —
// single Configure call per options type, combining section Bind with runtime overrides.
builder.Services.Configure<AcHubConnectionOptions>(opts => builder.Configuration.GetSection("AcHubConnection").Bind(opts));
builder.Services.Configure<AcHubConnectionOptions>(opts =>
{
builder.Configuration.GetSection("AcHubConnection").Bind(opts);
// Az fbHub URL a közös BaseUrl-ből (nem külön AcHubConnection:Url) — így nem tud eltérni a loggerHub-tól.
opts.Url = $"{FruitBankConstClient.BaseUrl}/{FruitBankConstClient.DefaultHubName}";
});
builder.Services.Configure<AcBinaryHubProtocolOptions>(opts =>
{

View File

@ -26,8 +26,7 @@
},
"AcHubConnection": {
"Url": "https://localhost:59579/fbHub",
//"Url": "https://shop.fruitbank.hu/fbHub",
// Az Url innen KIVÉVE: az fbHub és a loggerHub is az AyCode:Urls:BaseUrl-ből származik (kódban: +/fbHub, +/loggerHub).
"TransportMaxBufferSize": 30000000,
"ApplicationMaxBufferSize": 30000000,
"CloseTimeout": "00:00:10",

View File

@ -17,6 +17,10 @@ using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
// Hub-URL-ek EGY forrásból: az fbHub és a loggerHub is az AyCode:Urls:BaseUrl-ből származik.
FruitBankConstClient.BaseUrl = builder.Configuration["AyCode:Urls:BaseUrl"]
?? throw new InvalidOperationException("Hiányzik az 'AyCode:Urls:BaseUrl' az appsettings-ből — a hub-ok URL-je ebből származik.");
builder.Services.AddRazorComponents().AddInteractiveWebAssemblyComponents();
builder.Services.AddDevExpressBlazor(configure => configure.SizeMode = DevExpress.Blazor.SizeMode.Medium);
builder.Services.AddMvc();
@ -36,7 +40,12 @@ builder.Services.AddSingleton<LoggedInModel>(sp => new LoggedInModel(sp.GetRequi
// Bind SignalR options from appsettings.json — single Configure call per options type.
// The lambda runs the appsettings Bind first, then any runtime overrides (e.g. the WASM safety net).
builder.Services.Configure<AcHubConnectionOptions>(opts => builder.Configuration.GetSection("AcHubConnection").Bind(opts));
builder.Services.Configure<AcHubConnectionOptions>(opts =>
{
builder.Configuration.GetSection("AcHubConnection").Bind(opts);
// Az fbHub URL a közös BaseUrl-ből (nem külön AcHubConnection:Url) — így nem tud eltérni a loggerHub-tól.
opts.Url = $"{FruitBankConstClient.BaseUrl}/{FruitBankConstClient.DefaultHubName}";
});
builder.Services.Configure<AcBinaryHubProtocolOptions>(opts =>
{

View File

@ -26,8 +26,7 @@
},
"AcHubConnection": {
"Url": "https://localhost:59579/fbHub",
//"Url": "https://shop.fruitbank.hu/fbHub",
// Az Url innen KIVÉVE: az fbHub és a loggerHub is az AyCode:Urls:BaseUrl-ből származik (kódban: +/fbHub, +/loggerHub).
"TransportMaxBufferSize": 30000000,
"ApplicationMaxBufferSize": 30000000,
"CloseTimeout": "00:00:10",

View File

@ -1,6 +1,7 @@
using AyCode.Core.Enums;
using AyCode.Core.Loggers;
using AyCode.Services.SignalRs;
using FruitBank.Common;
using FruitBank.Common.Loggers;
using FruitBank.Common.Models;
using FruitBank.Common.Services;
@ -46,6 +47,10 @@ namespace FruitBankHybrid
}
}
// Hub-URL-ek EGY forrásból: az fbHub és a loggerHub is az AyCode:Urls:BaseUrl-ből származik.
FruitBankConstClient.BaseUrl = builder.Configuration["AyCode:Urls:BaseUrl"]
?? throw new InvalidOperationException("Hiányzik az 'AyCode:Urls:BaseUrl' az appsettings-ből — a hub-ok URL-je ebből származik.");
#if DEBUG
builder.Services.AddSingleton<IAcLogWriterClientBase, BrowserConsoleLogWriter>();
#endif
@ -59,7 +64,12 @@ namespace FruitBankHybrid
// Bind SignalR options from configuration.
// Precedence: code default → appsettings.json (this line) → any later Configure<T> action.
builder.Services.Configure<AcHubConnectionOptions>(builder.Configuration.GetSection("AcHubConnection"));
builder.Services.Configure<AcHubConnectionOptions>(opts =>
{
builder.Configuration.GetSection("AcHubConnection").Bind(opts);
// Az fbHub URL a közös BaseUrl-ből (nem külön AcHubConnection:Url) — így nem tud eltérni a loggerHub-tól.
opts.Url = $"{FruitBankConstClient.BaseUrl}/{FruitBankConstClient.DefaultHubName}";
});
builder.Services.Configure<AcBinaryHubProtocolOptions>(builder.Configuration.GetSection("AcBinaryHubProtocol"));
// Add device-specific services used by the FruitBankHybrid.Shared project