chenhaozhe
2026-11-11 5441ea196175b8a722632ad0b64ec8ff33209373
Merge branch 'master' of http://101.37.171.70:10101/r/APIGetway
4个文件已修改
20 ■■■■■ 已修改文件
APIGetway.csproj.user 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Program.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Properties/PublishProfiles/FolderProfile.pubxml.user 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
appsettings.json 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
APIGetway.csproj.user
@@ -2,7 +2,7 @@
<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>
Program.cs
@@ -10,6 +10,14 @@
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"));
@@ -24,6 +32,10 @@
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();
Properties/PublishProfiles/FolderProfile.pubxml.user
@@ -3,7 +3,7 @@
<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>
appsettings.json
@@ -21,6 +21,7 @@
    "Routes": {
      "mes-backend": {
        "ClusterId": "mes-backend",
        "CorsPolicy": "frontend-dev",
        "Match": {
          "Path": "/API/{**catch-all}"
        },
@@ -38,5 +39,8 @@
        }
      }
    }
    // 注意:YARP 没有 "CorsPolicies" 这个配置节(写了也会被静默忽略)。
    // 路由上的 "CorsPolicy" 只是策略名,真正的策略定义在 Program.cs 的 AddCors(...) 里,
    // 两处名字必须完全一致。
  }
}