File size: 2,368 Bytes
33cd1bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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();