Feature/base url in config (#234)

* started moving baseurl to config issue 233

* fixed test
This commit is contained in:
Tom Pallister
2018-02-15 09:52:16 +00:00
committed by GitHub
parent d6a86b9295
commit bf3188020a
9 changed files with 64 additions and 48 deletions

View File

@ -24,13 +24,21 @@ The following is a very basic configuration.json. It won't do anything but shoul
{
"ReRoutes": [],
"GlobalConfiguration": {}
"GlobalConfiguration": {
"BaseUrl": "https://api.mybusiness.com"
}
}
The most important thing to note here is BaseUrl. Ocelot needs to know the URL it is running under
in order to do Header find & replace and for certain administration configurations. When setting this URL it should be the external URL that clients will see Ocelot running on e.g. If you are running containers Ocelot might run on the url http://123.12.1.1:6543 but has something like nginx in front of it responding on https://api.mybusiness.com. In this case the Ocelot base url should be https://api.mybusiness.com.
If for some reason you are using containers and do want Ocelot to respond to client on http://123.12.1.1:6543
then you can do this but if you are deploying multiple Ocelot's you will probably want to pass this on the command line in some kind of script. Hopefully whatever scheduler you are using can pass the IP.
**Program**
Then in your Program.cs you will want to have the following. The main things to note are AddOcelotBaseUrl("http://localhost:5000") (adds the url this instance of Ocelot will run under),
AddOcelot() (adds ocelot services), UseOcelot().Wait() (sets up all the Ocelot middleware). It is important to call AddOcelotBaseUrl as Ocelot needs to know the URL that it is exposed to the outside world on.
Then in your Program.cs you will want to have the following. The main things to note are
AddOcelot() (adds ocelot services), UseOcelot().Wait() (sets up all the Ocelot middleware).
.. code-block:: csharp
@ -48,8 +56,7 @@ AddOcelot() (adds ocelot services), UseOcelot().Wait() (sets up all the Ocelot m
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddJsonFile("configuration.json")
.AddEnvironmentVariables()
.AddOcelotBaseUrl("http://localhost:5000");
.AddEnvironmentVariables();
})
.ConfigureServices(s => {
s.AddOcelot();
@ -68,15 +75,6 @@ AddOcelot() (adds ocelot services), UseOcelot().Wait() (sets up all the Ocelot m
}
}
AddOcelotBaseUrl
^^^^^^^^^^^^^^^^
The most important thing to note here is AddOcelotBaseUrl. Ocelot needs to know the URL it is running under
in order to do Header find & replace and for certain administration configurations. When setting this URL it should be the external URL that clients will see Ocelot running on e.g. If you are running containers Ocelot might run on the url http://123.12.1.1:6543 but has something like nginx in front of it responding on https://api.mybusiness.com. In this case the Ocelot base url should be https://api.mybusiness.com.
If for some reason you are using containers and do want Ocelot to respond to client on http://123.12.1.1:6543
then you can do this but if you are deploying multiple Ocelot's you will probably want to pass this on the command line in some kind of script. Hopefully whatever scheduler you are using can pass the IP.
.NET Core 1.0
^^^^^^^^^^^^^
@ -138,8 +136,7 @@ An example startup using a json file for configuration can be seen below.
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile("configuration.json")
.AddEnvironmentVariables()
.AddOcelotBaseUrl("http://localhost:5000");
.AddEnvironmentVariables();
Configuration = builder.Build();
}