[ad_1]
Separating monolithic app into several microservice now i’m interested how to run them all together.
So, I’m building ocelot gateway for this. And have some problems.
I tried to link one simple microservice with main api. If i go to the gateway route and query my microservices => i’ll get 404. However, if i go to the uri of that microservice i’ll get information.
Ocelot.json / ocelot.Development.json
{
"Routes": [
{
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
}
],
"DownstreamPathTemplate": "/order",
"DownstreamScheme": "https",
"UpstreamPathTemplate": "/order",
"UpstreamHttpMethod": [ "GET" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5001"
}
}
Program:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((hostingContext, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom
.Configuration(hostingContext.Configuration);
})
.ConfigureWebHostDefaults(webBuilder =>
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
webBuilder.ConfigureAppConfiguration(config =>
{
config
.AddJsonFile("ocelot.json")
.AddJsonFile($"ocelot.{environment}.json");
});
webBuilder.UseStartup<Startup>();
});
Startup:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
app.UseSerilogRequestLogging();
app.UseCors(_AllowSpecificOrigin);
app.UseSwagger(options =>
{
options.SerializeAsV2 = true;
});
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "ShoppingCart API");
options.RoutePrefix = string.Empty;
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapControllerRoute(
"default",
"{controller=Products}/{action=GetAll}/{id?}");
});
app.UseOcelot();
}
[ad_2]