| | |
| | | <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <PropertyGroup> |
| | | <ActiveDebugProfile>http</ActiveDebugProfile> |
| | | <NameOfLastUsedPublishProfile>F:\WorkBench\APIGetway\Properties\PublishProfiles\FolderProfile1.pubxml</NameOfLastUsedPublishProfile> |
| | | <NameOfLastUsedPublishProfile>F:\ProjFolder\APIGetway\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> |
| | | <DebuggerFlavor>ProjectDebugger</DebuggerFlavor> |
| | |
| | | |
| | | builder.Services.AddWindowsService(options => options.ServiceName = "APIGetway"); |
| | | |
| | | builder.Services.AddCors(options => |
| | | { |
| | | options.AddPolicy("frontend-dev", policy => policy |
| | | .WithOrigins("http://192.168.0.102:32976") // 换成前端真实地址+端口 |
| | | .WithMethods("GET", "POST", "PUT", "DELETE") |
| | | .WithHeaders("Content-Type", "X-Username", "Authorization")); |
| | | }); |
| | | |
| | | // YARP 反向代理 |
| | | builder.Services.AddReverseProxy() |
| | | .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")); |
| | |
| | | app.UseDefaultFiles(); |
| | | app.UseStaticFiles(); |
| | | |
| | | // 跨域中间件:YARP 路由带 CorsPolicy 时会往端点写 CORS 元数据, |
| | | // 缺了 UseCors 就会在请求时抛 "contains CORS metadata, but a middleware was not found" |
| | | app.UseCors(); |
| | | |
| | | // YARP 转发:按 appsettings.json 中的 Routes 规则转发到后端 |
| | | app.MapReverseProxy(); |
| | | |
| | |
| | | <Project> |
| | | <PropertyGroup> |
| | | <_PublishTargetUrl>D:\网站发布\智云MESWMS\APIGetway</_PublishTargetUrl> |
| | | <History>False|2026-11-09T01:48:19.1650763Z||;False|2026-11-09T09:48:16.4210302+08:00||;True|2026-11-05T15:24:01.6424731+08:00||;</History> |
| | | <History>True|2026-11-10T13:20:22.6009380Z||;False|2026-11-10T21:20:15.2216854+08:00||;True|2026-11-10T21:17:36.8635448+08:00||;True|2026-11-10T21:17:05.2126541+08:00||;True|2026-11-10T21:16:52.7350060+08:00||;True|2026-11-10T21:08:45.9397745+08:00||;True|2026-11-10T21:03:17.7382868+08:00||;False|2026-11-09T09:48:19.1650763+08:00||;False|2026-11-09T09:48:16.4210302+08:00||;True|2026-11-05T15:24:01.6424731+08:00||;</History> |
| | | <LastFailureDetails /> |
| | | </PropertyGroup> |
| | | </Project> |
| | |
| | | "Routes": { |
| | | "mes-backend": { |
| | | "ClusterId": "mes-backend", |
| | | "CorsPolicy": "frontend-dev", |
| | | "Match": { |
| | | "Path": "/API/{**catch-all}" |
| | | }, |
| | |
| | | } |
| | | } |
| | | } |
| | | // 注意:YARP 没有 "CorsPolicies" 这个配置节(写了也会被静默忽略)。 |
| | | // 路由上的 "CorsPolicy" 只是策略名,真正的策略定义在 Program.cs 的 AddCors(...) 里, |
| | | // 两处名字必须完全一致。 |
| | | } |
| | | } |
| | | } |