-
Hi i am using the ocelot json file in one of my API gateway, so i need to substitute values for the host/port for production environment which is different for DEV environment |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
Hi @saad569, one solution to differing hosts/ports could be to use an
"ReRoutes": [
{
"DownstreamPathTemplate": "/downstreampathtemplate",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "host.azurewebsites.net",
"Port": 443
}
],
"UpstreamHttpMethod": [
"Get"
],
"UpstreamPathTemplate": "/upstreampathtemplate"
}
]
"ReRoutes": [
{
"DownstreamPathTemplate": "/downstreampathtemplate",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5001
}
],
"UpstreamHttpMethod": [
"Get"
],
"UpstreamPathTemplate": "/upstreampathtemplate"
}
]
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureAppConfiguration((context, builder) =>
{
builder
.SetBasePath(context.HostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", true, true)
.AddJsonFile("ocelot.json", true, true)
.AddJsonFile($"ocelot.{context.HostingEnvironment.EnvironmentName}.json", true, true)
.AddEnvironmentVariables();
});
webBuilder.UseStartup<Startup>();
});
}
}
public class Startup
{
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.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
app.UseHsts();
app.UseHttpsRedirection();
app.UseOcelot().Wait();
}
} Alternatively, if you prefer to apply transformations as part of a pipeline, then you could use the Azure App Service Deploy task. See here for more information regarding how to substitute variables. |
Beta Was this translation helpful? Give feedback.
-
I tried your solution for using ocelot in azure. but somehow it is not working |
Beta Was this translation helpful? Give feedback.
-
Hi @AJCADamen, would you be able to elaborate on the issue that you are experiencing with this solution in more detail, for example by including your Ocelot configuration files and the build command that you are using to build the project? |
Beta Was this translation helpful? Give feedback.
-
I set up everything correctly for deploying to azure. Host and port and also the baseurl. And the gateway works locally. But as soon as it is deployed it fails. |
Beta Was this translation helpful? Give feedback.
-
Is there any chance that you could expand on the failure that you are experiencing when it is deployed? |
Beta Was this translation helpful? Give feedback.
Hi @saad569, one solution to differing hosts/ports could be to use an
ocelot.json
configuration file per environment, in a similar way to how theappsettings.json
files work.ocelot.json
(default)ocelot.Development.json
(development)