| | |
| | | var builder = WebApplication.CreateBuilder(args); |
| | | using Microsoft.Extensions.Hosting.WindowsServices; |
| | | using APIGetway.Filter; |
| | | |
| | | var builder = WebApplication.CreateBuilder(new WebApplicationOptions |
| | | { |
| | | Args = args, |
| | | // IIS 进程内托管时工作目录不是站点目录,固定为程序目录才能读到 appsettings.json |
| | | ContentRootPath = AppContext.BaseDirectory |
| | | }); |
| | | |
| | | builder.Services.AddWindowsService(options => options.ServiceName = "APIGetway"); |
| | | |
| | | // YARP 反向代理 |
| | | builder.Services.AddReverseProxy() |
| | |
| | | |
| | | var app = builder.Build(); |
| | | |
| | | // 拦截对 DLL/LOG 等敏感后缀的访问,直接返回 406(需在静态文件与反向代理之前) |
| | | app.UseFileExtensionFilter(); |
| | | |
| | | app.UseUpstreamErrorPageFilter(); |
| | | |
| | | app.UseDefaultFiles(); |
| | | app.UseStaticFiles(); |
| | | |
| | | // YARP 转发:匹配 /API_NW/ 前缀的请求转发到后端 |
| | | // YARP 转发:按 appsettings.json 中的 Routes 规则转发到后端 |
| | | app.MapReverseProxy(); |
| | | |
| | | app.Run(); |
| | | app.Run(); |