I want to use ocelot middleware with full dns address. But If I sent request to selected port postman says ECONNREFUSED. If I change the port it doesn't help me. I added ocelot.json and ocelot.developments.json file but it also doesn't help me. Note that I added to Routes directory two ocelot.some-api.json and ocelot.SwaggerEndPoint.json files. You can see the ocelot.json file below:
{
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5544"
},
"Routes": [
{
"UpstreamPathTemplate": "/gw/token",
"UpstreamHttpMethod": [ "POST" ],
"DownstreamPathTemplate": "/api/v2/users/get-token",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "some-selected-address.az"
"Port": 80
}
],
"SwaggerKey": "biosign"
}
],
"SwaggerEndPoints": [
{
"Key": "biosign",
"TransformByOcelotConfig": true,
"Config": [
{
"Name": "Biosign API",
"Version": "v1",
"Url": "http://some-selected-address.az/swagger/v1/swagger.json"
}
]
}
]
}
The Program.cs is:
using gateway_api.Config;
using MMLib.SwaggerForOcelot.DependencyInjection;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options => {
options.AddPolicy("CORSPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials().SetIsOriginAllowed((hosts) => true));
});
string routesDirectory = "Routes";
builder.Configuration.AddOcelotWithSwaggerSupport(options => { options.Folder = routesDirectory; });
builder.Services.AddOcelot(builder.Configuration);
builder.Services.AddSwaggerForOcelot(builder.Configuration);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.ResolveConflictingActions(p => p.FirstOrDefault());
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
}
#region Remove in future
app.UseDeveloperExceptionPage();
#endregion
app.UseAuthorization();
app.UseSwaggerForOcelotUI(options =>
{
options.PathToSwaggerGenerator = "/swagger/docs";
options.ReConfigureUpstreamSwaggerJson = AlterUpstream.AlterUpstreamSwaggerJson;
});
app.UseOcelot().Wait();
app.MapControllers();
//app.UseCors("CORSPolicy");
app.Run();