Files
KinginfoGateway/src/Admin/ThingsGateway.AdminServer/Program/Program.cs
2025-05-31 02:17:09 +08:00

114 lines
4.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://thingsgateway.cn/
// QQ群605534569
//------------------------------------------------------------------------------
using Microsoft.AspNetCore.ResponseCompression;
using System.Runtime.InteropServices;
using System.Text;
using ThingsGateway.NewLife.Log;
namespace ThingsGateway.AdminServer;
public class Program
{
private static readonly string[] second = new[] { "application/octet-stream" };
public static async Task Main(string[] args)
{
await Task.Delay(2000).ConfigureAwait(false);
//当前工作目录设为程序集的基目录
System.IO.Directory.SetCurrentDirectory(AppContext.BaseDirectory);
// 增加中文编码支持
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#region Logo
Console.Write(Environment.NewLine);
Console.ForegroundColor = ConsoleColor.Yellow;
XTrace.WriteLine(string.Empty);
XTrace.UseConsole();
Console.WriteLine(
"""
_______ _ _ _____ _
|__ __|| | (_) / ____| | |
| | | |__ _ _ __ __ _ ___ | | __ __ _ | |_ ___ __ __ __ _ _ _
| | | '_ \ | || '_ \ / _` |/ __|| | |_ | / _` || __|/ _ \\ \ /\ / // _` || | | |
| | | | | || || | | || (_| |\__ \| |__| || (_| || |_| __/ \ V V /| (_| || |_| |
|_| |_| |_||_||_| |_| \__, ||___/ \_____| \__,_| \__|\___| \_/\_/ \__,_| \__, |
__/ | __/ |
|___/ |___/
"""
);
Console.ResetColor();
#endregion Logo
await Serve.RunAsync(RunOptions.Default.ConfigureFirstActionBuilder(builder =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
builder.Host.UseWindowsService();
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
builder.Host.UseSystemd();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
builder.Logging.ClearProviders(); //去除默认的事件日志提供者,某些情况下会日志输出异常,导致程序崩溃
}).ConfigureBuilder(builder =>
{
if (!builder.Environment.IsDevelopment())
{
builder.Services.AddResponseCompression(
opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(second);
});
}
builder.WebHost.UseWebRoot("wwwroot");
builder.WebHost.UseStaticWebAssets();
// 设置接口超时时间和上传大小-Kestrel
builder.WebHost.ConfigureKestrel(u =>
{
u.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
u.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(30);
u.Limits.MaxRequestBodySize = null;
});
})
.Configure(app =>
{
#if NET8_0_OR_GREATER
app.MapRazorComponents<BlazorApp>()
.AddAdditionalAssemblies(App.RazorAssemblies.Distinct().Where(a => a != typeof(Program).Assembly).ToArray())
.AddInteractiveServerRenderMode();
#else
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
#endif
})
).ConfigureAwait(false);
}
}