chenhaozhe
2026-11-09 e0da2f80699c966fb3cf95bae9fbba88e5406ac9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using Microsoft.Extensions.Hosting.WindowsServices;
 
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
    Args = args,
    ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : null
});
 
builder.Services.AddWindowsService(options => options.ServiceName = "APIGetway");
 
// YARP 反向代理
builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
 
var app = builder.Build();
 
app.UseDefaultFiles();
app.UseStaticFiles();
 
// YARP 转发:匹配 /API_NW/ 前缀的请求转发到后端
app.MapReverseProxy();
 
app.Run();