-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle non-root gateway? #194
Comments
Hi, Do you have a base url set in Minimal working example: Ocelot.json{
"Routes": [
{
"DownstreamPathTemplate": "/api/v1/settings/{everything}",
"UpstreamPathTemplate": "/api/v1/settings/{everything}",
"SwaggerKey": "settings"
}
],
"SwaggerEndPoints": [
{
"Key": "settings",
"Config": [
{
"Name": "My Settings API",
"Version": "v1",
"Url": "http://localhost:5100/swagger/v1/swagger.json"
}
]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000/mygateway"
} Startup.cspublic void ConfigureServices(IServiceCollection services)
{
services.AddOcelot();
services.AddSwaggerForOcelot(Configuration);
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UsePathBase("/mygateway");
app.UseSwaggerForOcelotUI()
.UseOcelot()
.Wait();
} |
We had set the base path in ocelot.json. But adding it in code using |
Hello. Did it solve your problem? { |
Hi |
Thanks for your answer. Do you have correct urls in your swagger.json for downstream service? My urls don't have prefix "basepath". |
The 'basepath' is called 'testpath' in my sample for the downstream service. The virtual directory / application directory of the ocelot gateway is 'ocelotpath' in my sample.
|
@Burgyn Hi, I tried your minimal example, but I didn't have correct urls for downstream services. For example for instead of "mygateway/api/Books", I get just "/api/Books" without ocelot.js
Program.cs
|
@leonluc-dev did you solve your problem? |
@alex-tselikovsky None of the above worked for me. Had to do something like:
|
I have the following scenario: My API Gateways run, within a path of my subdomain:
My configuration file is very simple:
And I was facing the same problem reported in this issue, I tried the solutions that were reported:
I wasn't successful with any of them and I ended up following the solution that @liamharper2453 commented on:
I understand that it's not the best solution, but it's the one I managed to make work, if anyone has a better solution I accept suggestions. |
I have a question regarding the handling of swagger generation when the Ocelot gateway endpoint is not on root.
Using the following ocelot.json:
In code the SwaggerForOcelot setup is very basic:
Ocelot itself works fine with this setup.
However, whenever we open the swagger documentation at
https://myapi.com/mygateway/swagger/index.html
the page starts loading but it tries to load the subdocuments athttps://myapi.com/swagger/docs
rather than the expectedhttps://myapi.com/mygateway/swagger/docs
. This causes the page to not load fully and show a fetch error.Is there a way to set the base url which SwaggerForOcelot should use for the gateway (or how to make it use the Ocelot baseUrl)?
We've tried something like
opt.DownstreamSwaggerEndPointBasePath = "../swagger/docs";
as suggested in issue #113, and while this solved the loading of documents, it doesn't fix the urls in the generated document itself. Those still go for the root and therefore the calls fail with a 404:The text was updated successfully, but these errors were encountered: