Skip to content

Commit

Permalink
为了兼容旧版本,优先给它ApiHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jul 3, 2024
1 parent 98aa4b9 commit 84c557d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Stardust.Extensions/TracerMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,21 @@ public static void SaveServiceAddress(HttpContext ctx)
var uri = ctx.Request.GetRawUrl();
if (uri == null) return;

// 排除本机地址
var host = uri.Authority;
var p = host.LastIndexOf(':');
if (p >= 0) host = host[..p];
if (host.EqualIgnoreCase("127.0.0.1", "localhost", "[::1]")) return;

var baseAddress = $"{uri.Scheme}://{uri.Authority}";

var set = NewLife.Setting.Current;
var ss = set.ServiceAddress.Split(",").ToList();
if (!ss.Contains(baseAddress))
{
// 过滤掉本机地址
ss = ss.Where(e => !e.EqualIgnoreCase("127.0.0.1", "localhost", "[::1]")).ToList();

ss.Insert(0, baseAddress);
set.ServiceAddress = ss.Take(3).Join(",");
set.Save();
Expand Down
2 changes: 2 additions & 0 deletions Stardust.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

Usewwwroot(app, env);

app.UseStardust();

// 缓存运行时安装文件
var set = StarServerSetting.Current;
if (!set.FileCache.IsNullOrEmpty())
Expand Down
5 changes: 5 additions & 0 deletions Stardust/StarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ public IConfigProvider? Config
//if (!ClientId.IsNullOrEmpty()) config.ClientId = ClientId;
config.Attach(_client);

// 为了兼容旧版本,优先给它ApiHttpClient
var ver = typeof(HttpConfigProvider).Assembly.GetName().Version;
if (ver <= new Version(10, 10, 2024, 0701) && _client.Client is ApiHttpClient client)
config.Client = client;

//!! 不需要默认加载,直到首次使用配置数据时才加载。因为有可能应用并不使用配置中心,仅仅是获取这个对象。避免网络不通时的报错日志
//config.LoadAll();

Expand Down

0 comments on commit 84c557d

Please sign in to comment.