How to define URL of Ocelot API Gateway
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:
- http:///api/
- http:///api/a/customer
- http:///a/api/customer
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.APIDockerfile
subscribe.api:
image: ${DOCKER_REGISTRY}subscribe.api
build:
context: .
dockerfile: NewsSubscibe.APIDockerfile
unsubscribe.api:
image: ${DOCKER_REGISTRY}unsubscribe.api
build:
context: .
dockerfile: NewsUnSubscribe.APIDockerfile
gateway:
image: gateway
build:
context: ./OcelotAPIGateway
dockerfile: Dockerfile
depends_on:
- customer.api
- subscribe.api
- unsubscribe.api
docker asp.net-core .net-core ocelot
add a comment |
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:
- http:///api/
- http:///api/a/customer
- http:///a/api/customer
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.APIDockerfile
subscribe.api:
image: ${DOCKER_REGISTRY}subscribe.api
build:
context: .
dockerfile: NewsSubscibe.APIDockerfile
unsubscribe.api:
image: ${DOCKER_REGISTRY}unsubscribe.api
build:
context: .
dockerfile: NewsUnSubscribe.APIDockerfile
gateway:
image: gateway
build:
context: ./OcelotAPIGateway
dockerfile: Dockerfile
depends_on:
- customer.api
- subscribe.api
- unsubscribe.api
docker asp.net-core .net-core ocelot
add a comment |
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:
- http:///api/
- http:///api/a/customer
- http:///a/api/customer
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.APIDockerfile
subscribe.api:
image: ${DOCKER_REGISTRY}subscribe.api
build:
context: .
dockerfile: NewsSubscibe.APIDockerfile
unsubscribe.api:
image: ${DOCKER_REGISTRY}unsubscribe.api
build:
context: .
dockerfile: NewsUnSubscribe.APIDockerfile
gateway:
image: gateway
build:
context: ./OcelotAPIGateway
dockerfile: Dockerfile
depends_on:
- customer.api
- subscribe.api
- unsubscribe.api
docker asp.net-core .net-core ocelot
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:
- http:///api/
- http:///api/a/customer
- http:///a/api/customer
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.APIDockerfile
subscribe.api:
image: ${DOCKER_REGISTRY}subscribe.api
build:
context: .
dockerfile: NewsSubscibe.APIDockerfile
unsubscribe.api:
image: ${DOCKER_REGISTRY}unsubscribe.api
build:
context: .
dockerfile: NewsUnSubscribe.APIDockerfile
gateway:
image: gateway
build:
context: ./OcelotAPIGateway
dockerfile: Dockerfile
depends_on:
- customer.api
- subscribe.api
- unsubscribe.api
docker asp.net-core .net-core ocelot
docker asp.net-core .net-core ocelot
asked Nov 21 '18 at 15:11
Emin HasanovEmin Hasanov
6431619
6431619
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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();
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415039%2fhow-to-define-url-of-ocelot-api-gateway%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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();
}
add a comment |
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();
}
add a comment |
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();
}
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();
}
answered Nov 26 '18 at 21:39
Roman MarusykRoman Marusyk
12.1k123668
12.1k123668
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415039%2fhow-to-define-url-of-ocelot-api-gateway%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown