Video_Depth / Program.cs
DannyChi's picture
Upload Program.cs
a36260e verified
using Microsoft.AspNetCore.StaticFiles;
var builder = WebApplication.CreateBuilder(args);
// �K�[ CORS ����
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
// �K�[ HttpClient �u�t
builder.Services.AddHttpClient();
// �W�[ HttpClient �u�t�A�ðt�m�R�W�� HttpClient
builder.Services.AddHttpClient("VideoProcessingClient")
.SetHandlerLifetime(TimeSpan.FromMinutes(5)) // �i��G�]�m�B�z�{�Ǫ��ͩR�g��
.ConfigurePrimaryHttpMessageHandler(() =>
{
// �i��G�t�m�۩w�q�� HttpMessageHandler�A�Ҧp Proxy�BSSL ��
return new HttpClientHandler();
})
.ConfigureHttpClient(client =>
{
client.Timeout = TimeSpan.FromMinutes(10); // �]�m�W�ɬ� 10 ����
});
// Add services to the container.
builder.Services.AddControllers();
// �]�w�̤j�ШD��j�p�]�Ҧp�A1 GB�^
builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxRequestBodySize = 1073741824; // 1 GB
options.ListenAnyIP(7860); // �u�O�d HTTP �Y�i
//options.ListenAnyIP(7860, listenOptions =>
//{
// listenOptions.UseHttps(); // ��ť HTTPS 8081 �ݤf
//});
});
var app = builder.Build();
// �ϥ� CORS
app.UseCors("AllowAll");
// �]�w `.onnx` �� MIME ����
var provider = new FileExtensionContentTypeProvider();
//provider.Mappings[".onnx"] = "application/octet-stream";
provider.Mappings[".wasm"] = "application/wasm"; // �� WebAssembly �K�[ MIME ����
provider.Mappings[".data"] = "application/data"; // �� WebAssembly �K�[ MIME ����
// �ϥ� DefaultFiles ������M�� index.html
app.UseDefaultFiles();
// �����R�A���A�èϥΦۭq�� MIME �������Ѫ̻P���Y
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider,
OnPrepareResponse = ctx =>
{
Console.WriteLine($"Serving file: {ctx.File.PhysicalPath}");
// �[�J COOP �P COEP ���Y
ctx.Context.Response.Headers["Cross-Origin-Opener-Policy"] = "same-origin";
ctx.Context.Response.Headers["Cross-Origin-Embedder-Policy"] = "require-corp";
}
});
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();