Reputation: 1362
I have three ASP.NET Core WebAPI services Customer, Subscribe, Unscubscribe with swashbuckle and docker compose project All is working well I have added Ocelot API Gateway (ASP.NET core Project) with Ocelot installed.
Access customer service via own address https:///api/Customer works great. But from gateway I don't know which url should I use for example this customer service I have tried many variants like:
but all of them returns 404. May be problem with that Gateway is http not https?
Program.cs
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
var builder = WebHost.CreateDefaultBuilder(args);
builder.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration(
ic => ic.AddJsonFile(Path.Combine("configuration",
"configuration.json")))
.UseStartup<Startup>();
var host = builder.Build();
return host;
}
Startup.cs
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);
services.AddOcelot(Configuration);
}
// 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();
}
Configurations:
configuration.json:
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/",
"DownstreamScheme": "http",
"DownstreamPort": 80,
"DownstreamHost": "customer.api",
"UpstreamPathTemplate": "/a/",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ]
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamPort": 80,
"DownstreamHost": "customer.api",
"UpstreamPathTemplate": "/a/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ]
},
{
"DownstreamPathTemplate": "/",
"DownstreamScheme": "http",
"DownstreamPort": 80,
"DownstreamHost": "subscribe.api",
"UpstreamPathTemplate": "/b/",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ]
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamPort": 80,
"DownstreamHost": "subscribe.api",
"UpstreamPathTemplate": "/b/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ]
},
{
"DownstreamPathTemplate": "/",
"DownstreamScheme": "http",
"DownstreamPort": 80,
"DownstreamHost": "unsubscribe.api",
"UpstreamPathTemplate": "/c/",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ]
},
{
"DownstreamPathTemplate": "/{everything}",
"DownstreamScheme": "http",
"DownstreamPort": 80,
"DownstreamHost": "unsubscribe.api",
"UpstreamPathTemplate": "/c/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Options" ]
}
],
"GlobalConfiguration": {}
}
docker-compose.yml:
services:
customer.api:
image: ${DOCKER_REGISTRY}customer.api
build:
context: .
dockerfile: Customer.API\Dockerfile
subscribe.api:
image: ${DOCKER_REGISTRY}subscribe.api
build:
context: .
dockerfile: NewsSubscibe.API\Dockerfile
unsubscribe.api:
image: ${DOCKER_REGISTRY}unsubscribe.api
build:
context: .
dockerfile: NewsUnSubscribe.API\Dockerfile
gateway:
image: gateway
build:
context: ./OcelotAPIGateway
dockerfile: Dockerfile
depends_on:
- customer.api
- subscribe.api
- unsubscribe.api
Upvotes: 2
Views: 5369
Reputation: 24619
You need to add UseOcelot().Wait();
in Configure method of Startup:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
app.UseOcelot().Wait();
}
Upvotes: 4