Skip to content
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

Failing to ReRoutes leads to 404 when omitting "/api/" in get url #465

Closed
Ehrys opened this issue Jul 11, 2018 · 7 comments
Closed

Failing to ReRoutes leads to 404 when omitting "/api/" in get url #465

Ehrys opened this issue Jul 11, 2018 · 7 comments
Labels
question Initially seen a question could become a new feature or bug or closed ;)

Comments

@Ehrys
Copy link

Ehrys commented Jul 11, 2018

As part of a test in order to later use Ocelot, I built a mock project using " https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core/ ", updated it to work with NetCore 2.1/Ocelot 8 and started playing with it.

The project is a Core console project as gateway using 2 core web api (except for names, they're identical thanks to copy paste).

I have a problem with ReRouting one of the API I'm using. I can access the "customers" api using localhost:5000/customers but I have to use localhost:5000/api/products if I want to access the "products" one. Note that I can access BOTH of them (but with an unexpected route for one).

Am I missing something ?

This is the Gateway.zip project (ocelot.json included), let me know if you need anything else.

Thanks !

Expected Behavior

Free access to "products" without having to put "/api/" in the url.

Actual Behavior

404 when trying to access localhost:5000/products.

Specifications

  • Version: 8 (NuGet VS2017)
@Ehrys
Copy link
Author

Ehrys commented Jul 11, 2018

Ok, I just found something using another project. There's a difference between the ocelot.json I want to use and the one used in the bin folder (looks generated).

Any help on setting this up so the file used is the one I edit please ?

THanks !

@Ehrys
Copy link
Author

Ehrys commented Jul 11, 2018

Further investigation lead to a fix. Simply renamed my ocelot.json to oselot.global.json.

From the sample I've seen on github, it might be a bug. Any feedback appreciated !

Thanks !

@anktsrkr
Copy link
Contributor

Hi @Ehrys , I don't think, it is a bug, rather it's a feature, Please check #296 for more details, and Here is the documentation.

Thanks.

@TomPallister
Copy link
Member

@Ehrys thanks for your interest in Ocelot.
@anktsrkr thanks for helping me!! I really appreciate the support.

You should have a ocelot.json for each environment you want to work in e.g. ocelot.development.json, ocelot.staging.json, ocelot.production.json or something.

However you should just be able to add ocelot.json and everything will work ok if you do

.AddJsonFile("ocelot.json")

Let me know if you are still having problems?

@TomPallister TomPallister added the question Initially seen a question could become a new feature or bug or closed ;) label Jul 12, 2018
@Ehrys
Copy link
Author

Ehrys commented Jul 16, 2018

@anktsrkr as per @TomPallister I was expecting having only the ocelot.json file to work (as it's supposed to work when using .AddJsonFile but seems not to be working with AddOcelot).

@TomPallister I fixed it by renaming my ocelot.json to ocelot.global.json, anyway I was expecting the AddOcelot to work with a simple ocelot.json file but I missread the doc's regex (note that "ocelot..json" matches the doc's regex).

Thank you both for your help !

@Ehrys Ehrys closed this as completed Jul 16, 2018
@the-matty-b
Copy link

the-matty-b commented Jul 23, 2021

However you should just be able to add ocelot.json and everything will work ok if you do

.AddJsonFile("ocelot.json")

Let me know if you are still having problems?

Where the heck do you put this .addJsonFile("ocelot.json") ? Everyone says "oh yeah use this", but they never say where!

@computerprince
Copy link

However you should just be able to add ocelot.json and everything will work ok if you do

.AddJsonFile("ocelot.json")

Let me know if you are still having problems?

Where the heck do you put this .addJsonFile("ocelot.json") ? Everyone says "oh yeah use this", but they never say where!

you need to put inside the program.cs or startup.cs for example in program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json",
optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.local.json", optional: true, reloadOnChange: true)
.AddJsonFile("ocelot.json")
.AddEnvironmentVariables();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();

            });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Initially seen a question could become a new feature or bug or closed ;)
Projects
None yet
Development

No branches or pull requests

5 participants