87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using Hi.Disp;
|
|
using Hi.Licenses;
|
|
using Hi.Webapi.Hubs;
|
|
using Hi.Webapi.Services;
|
|
|
|
namespace Hi.Webapi
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
License.LogInAll();
|
|
DispEngine.Init();
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddOpenApi();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
// 添加 SignalR
|
|
builder.Services.AddSignalR(options =>
|
|
{
|
|
options.MaximumReceiveMessageSize = 10 * 1024 * 1024; // 10MB
|
|
});
|
|
|
|
// 添加 CORS
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("AllowAll", policy =>
|
|
{
|
|
policy.AllowAnyOrigin()
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader();
|
|
});
|
|
});
|
|
|
|
// 註冊 RenderingService
|
|
builder.Services.AddSingleton<RenderingService>();
|
|
|
|
// 配置允許 unsafe 代碼
|
|
builder.Services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(options =>
|
|
{
|
|
options.AllowSynchronousIO = true;
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure application lifetime events
|
|
var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
|
|
lifetime.ApplicationStopping.Register(() =>
|
|
{
|
|
DispEngine.FinishDisp();
|
|
License.LogOutAll();
|
|
Console.WriteLine($"App exit.");
|
|
});
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
// 在開發環境中不使用 HTTPS 重定向
|
|
// app.UseHttpsRedirection();
|
|
|
|
// 添加靜態文件支援
|
|
app.UseStaticFiles();
|
|
|
|
app.UseCors("AllowAll");
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
// 映射 SignalR Hub
|
|
app.MapHub<RenderingHub>("/renderingHub");
|
|
|
|
// 添加一個簡單的首頁
|
|
app.MapGet("/", () => Results.Redirect("/demo-vue.html"));
|
|
|
|
app.Run();
|
|
}
|
|
}
|
|
}
|