init
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
using Hi.HiNcKits;
|
||||
using Hi.Webapi.Hubs;
|
||||
using Hi.Webapi.Services;
|
||||
|
||||
SingleUserApp.AppBegin();
|
||||
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();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// 添加 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(() =>
|
||||
{
|
||||
SingleUserApp.AppEnd();
|
||||
});
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
// 在開發環境中不使用 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();
|
||||
Reference in New Issue
Block a user