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

View File

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

View File

@ -18,6 +18,11 @@ using Microsoft.Extensions.Options;
var builder = WebAssemblyHostBuilder.CreateDefault(args); 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); builder.Services.AddDevExpressBlazor(configure => configure.SizeMode = DevExpress.Blazor.SizeMode.Medium);
// Add device-specific services used by the FruitBankHybrid.Shared project // 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) — // Bind SignalR options from wwwroot/appsettings.json (loaded automatically by WebAssemblyHostBuilder) —
// single Configure call per options type, combining section Bind with runtime overrides. // 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 => builder.Services.Configure<AcBinaryHubProtocolOptions>(opts =>
{ {

View File

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

View File

@ -17,6 +17,10 @@ using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args); 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.AddRazorComponents().AddInteractiveWebAssemblyComponents();
builder.Services.AddDevExpressBlazor(configure => configure.SizeMode = DevExpress.Blazor.SizeMode.Medium); builder.Services.AddDevExpressBlazor(configure => configure.SizeMode = DevExpress.Blazor.SizeMode.Medium);
builder.Services.AddMvc(); 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. // 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). // 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 => builder.Services.Configure<AcBinaryHubProtocolOptions>(opts =>
{ {

View File

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

View File

@ -1,6 +1,7 @@
using AyCode.Core.Enums; using AyCode.Core.Enums;
using AyCode.Core.Loggers; using AyCode.Core.Loggers;
using AyCode.Services.SignalRs; using AyCode.Services.SignalRs;
using FruitBank.Common;
using FruitBank.Common.Loggers; using FruitBank.Common.Loggers;
using FruitBank.Common.Models; using FruitBank.Common.Models;
using FruitBank.Common.Services; 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 #if DEBUG
builder.Services.AddSingleton<IAcLogWriterClientBase, BrowserConsoleLogWriter>(); builder.Services.AddSingleton<IAcLogWriterClientBase, BrowserConsoleLogWriter>();
#endif #endif
@ -59,7 +64,12 @@ namespace FruitBankHybrid
// Bind SignalR options from configuration. // Bind SignalR options from configuration.
// Precedence: code default → appsettings.json (this line) → any later Configure<T> action. // 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")); builder.Services.Configure<AcBinaryHubProtocolOptions>(builder.Configuration.GetSection("AcBinaryHubProtocol"));
// Add device-specific services used by the FruitBankHybrid.Shared project // Add device-specific services used by the FruitBankHybrid.Shared project