Skip to content

Commit 2657c88

Browse files
committed
feat(HTTP服务): 添加HTTP服务启用开关配置
在AppSetting和LauncherOptions中添加IsEnableHttp配置项,用于控制是否启用HTTP服务 在AppStartUpByHTTPServer中增加检查逻辑,当服务禁用时跳过启动
1 parent a8599ab commit 2657c88

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

GameFrameX.StartUp/AppStartUpByHTTPServer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public abstract partial class AppStartUpBase
6464
/// <exception cref="NotImplementedException">当启用HTTPS但未实现时抛出</exception>
6565
private async Task StartHttpServer(List<BaseHttpHandler> baseHandler, Func<string, BaseHttpHandler> httpFactory, List<IHttpAopHandler> aopHandlerTypes = null, LogLevel minimumLevelLogLevel = LogLevel.Debug)
6666
{
67+
// 检查是否启用HTTP服务
68+
if (!Setting.IsEnableHttp)
69+
{
70+
LogHelper.InfoConsole("The HTTP service is disabled, and the startup is ignored");
71+
return;
72+
}
73+
6774
// 验证HTTP URL格式
6875
if (!Setting.HttpUrl.StartsWith('/'))
6976
{

GameFrameX.StartUp/Options/LauncherOptions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ public sealed class LauncherOptions
270270
public ushort DataCenterId { get; set; }
271271

272272
/// <summary>
273-
/// API接口根路径,必须以/开头和以/结尾,默认为[/game/api/]
273+
/// 是否启用 HTTP 服务,默认值为 true
274+
/// <para>开启后服务器将监听 HTTP 端口,允许客户端通过 HTTP 协议进行连接</para>
275+
/// <para>默认值为 true,即启用,因为健康检查需要通过 HTTP 端口进行访问</para>
274276
/// </summary>
275-
[Option(nameof(HttpUrl), DefaultValue = "/game/api/", Description = "API接口根路径,必须以/开头和以/结尾,默认为[/game/api/]")]
276-
public string HttpUrl { get; set; }
277+
[Option(nameof(IsEnableHttp), DefaultValue = true, Description = "是否启用 HTTP 服务,默认值为 true")]
278+
public bool IsEnableHttp { get; set; } = true;
277279

278280
/// <summary>
279281
/// HTTP 是否是开发模式,当是开发模式的时候将会启用Swagger
@@ -282,6 +284,12 @@ public sealed class LauncherOptions
282284
// [GrafanaLokiLabelTag]
283285
public bool HttpIsDevelopment { get; set; }
284286

287+
/// <summary>
288+
/// API接口根路径,必须以/开头和以/结尾,默认为[/game/api/]
289+
/// </summary>
290+
[Option(nameof(HttpUrl), DefaultValue = "/game/api/", Description = "API接口根路径,必须以/开头和以/结尾,默认为[/game/api/]")]
291+
public string HttpUrl { get; set; }
292+
285293
/// <summary>
286294
/// HTTP 端口
287295
/// </summary>

GameFrameX.Utility/Setting/AppSetting.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ public string ToFormatString()
299299
/// </summary>
300300
public string HttpUrl { get; set; }
301301

302+
/// <summary>
303+
/// 是否启用 HTTP 服务
304+
/// </summary>
305+
public bool IsEnableHttp { get; set; }
306+
302307
/// <summary>
303308
/// HTTP 是否是开发模式
304309
/// </summary>

0 commit comments

Comments
 (0)