繁体   English   中英

.NET 6 Ocelot:对 Ocelot 端点的请求返回 404

[英].NET 6 Ocelot: requests to Ocelot's enpoints return 404

我的项目中有一个 Ocelot 网关,目前只有一个微服务 UserService。 它可以正常工作。 但我在网关项目中也有一个 controller:

User
|
+-Controllers
  |
  +-UserController.cs

Gateway
|
+-Controllers
  |
  +-AuthController.cs

有我的ocelot.json。 就像我说的那样,“/api/user/ ”可以正常工作,而“/api/auth/ ”曾经在单独的项目中工作,当然有不同的端口。 但是现在的设置是:

{
  "GlobalConfiguration": {
    "BaseUrl": "https://localhost:7259"
  },
  "Routes": [
    {
      "UpstreamPathTemplate": "/api/auth/{everything}",
      "UpstreamHttpMethod": [ "Get" ],
      "DownstreamPathTemplate": "/Auth/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 7259
        }
      ]
    },
    {
      "UpstreamPathTemplate": "/api/user/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
      "DownstreamPathTemplate": "/User/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 7244
        }
      ]
    }
  ]
}

这是我的 Program.cs,如果需要的话:

using Ocelot.DependencyInjection;
using Ocelot.Middleware;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Configuration.AddJsonFile("ocelot.json");
builder.Services.AddOcelot(builder.Configuration);

builder.Services.AddScoped<IAuthService, AuthService>();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

await app.UseOcelot();

app.UseAuthorization();

app.MapControllers();

app.Run();

当我运行此配置时,“/api/auth/ ”(与基本 AuthController 地址相同 - “/Auth/ ”)返回 404。我应该如何配置 Ocelot 的项目自己的控制器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM