我正在尝试实现我的微服务应用程序。我在 localhost:5001 上的目录 API 微服务 - 基础 CRUD。我想使用 Ocelot 实现 Api Gateway。
Catalo.API launSettings.json:
"reservation_system.Catalo.Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger/index.html",
"applicationUrl": "http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
来自 API 网关的 Program.cs:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) =>
{
config
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{host.HostingEnvironment.EnvironmentName}.json", true, true)
.AddEnvironmentVariables();
config.AddJsonFile("configuration.json");
})
.UseStartup<Startup>();
}
启动.cs
public class Startup
{
public IConfiguration Configuration { get; set; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddOcelot();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
app.UseMvc();
await app.UseOcelot();
}
}
我正在尝试通过http://localhost:50121/catalog访问我的目录 API 我得到“Hello World!” 回答。这里有什么问题?