Создание архитектуры микроуслуг с помощью Ocelot Я начал создавать тестовый сервис в отдельном решении.Все работает, и я могу получить ложный ответ на https://localhost:5101/service/stats/collected
.
Затем в другом решении я делаю новый новый проект webapi.Затем я следую за началом работы на официальном сайте Ocelot .
. Конфигурирование файла .json для использования в качестве GW Я получил 500 от проекта, если я попробуюударить https://localhost:5001/api/stats/collected
и я не могу понять, почему?
Вот основные файлы для APIGW:
ocelot.json
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/service/stats/collected",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5101
}
],
"UpstreamPathTemplate": "/api/stats/collected"
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5001"
}
}
Program.cs
using System.IO;
using System.Net;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
namespace APIGateway.Base
{
public class Program
{
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel(
options =>
{
options.Listen(IPAddress.Loopback, 5001, listenOptions =>
{
listenOptions.UseHttps("localhost.pfx", "qwerty123");
});
options.AddServerHeader = false;
}
)
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddJsonFile("ocelot.json")
.AddEnvironmentVariables();
})
.ConfigureServices(s => {
s.AddOcelot();
})
.ConfigureLogging((hostingContext, logging) =>
{
//add your logging
})
.UseIISIntegration()
.Configure(app =>
{
app.UseOcelot().Wait();
})
.Build()
.Run();
}
}
}
Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace StatsService.Base
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
}
}
ОБНОВЛЕНИЕ:
Я узнаю, что отключение SSL для каждого проекта, комментируя options
в методе UseKestrel
, заставляет мой GW работать.Как я могу настроить это, чтобы иметь безопасную связь между моим GW и Сервисом?Локальный хост и Прод?