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

134 dynamic gateway reconfiguration #174

Merged
merged 14 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP testing YARP and Ocelot
  • Loading branch information
radu-popescu committed Jun 20, 2023
commit cd5205fcf4b357eaa939341d75064f7a46406e55
69 changes: 69 additions & 0 deletions src/OcelotGateway/Controllers/RouteController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Yarp.ReverseProxy.Configuration;
using Microsoft.AspNetCore.Routing;


namespace Middleware.OcelotGateway.Controllers;


[Route("api/v1")]
[ApiController]
public class RouteController : ControllerBase
{
private readonly InMemoryConfigProvider _inMemoryConfigProvider;

public string RouteId { get; set; }

public string ClusterId { get; set; }



public RouteController(IProxyConfigProvider inMemoryConfigProvider)
{
if (inMemoryConfigProvider is InMemoryConfigProvider imcp)
_inMemoryConfigProvider = imcp;
}


[HttpGet]
[Route("hello", Name = "Hello")]
public IActionResult Hello()
{
return Ok("hello");
}

[HttpPost]
[Route("configure", Name = "CreateDynamicRoute")]
public IActionResult CreateDynamicRoute()
{
var config = _inMemoryConfigProvider.GetConfig();

var clusterList = config.Clusters.ToList();
var routeList = config.Routes.ToList();

ClusterConfig clusterCfg = new ClusterConfig
{
ClusterId = "testCluster",
Destinations = new Dictionary<string, DestinationConfig>
{
{ "testdest1", new DestinationConfig{Address = "http://localhost/api/v1/hello"} }
}
};
RouteConfig routecfg = new RouteConfig()
{
RouteId = "test",
Match = new RouteMatch
{
Path = "my/test/endpoint"
}
};
clusterList.Add(clusterCfg);
routeList.Add(routecfg);

_inMemoryConfigProvider.Update(routeList, clusterList);

return Ok();
}

}
24 changes: 24 additions & 0 deletions src/OcelotGateway/ocelot.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@
"UpstreamPathTemplate": "/Register",
"UpstreamHttpMethod": [ "POST" ]
},
{
"DownstreamPathTemplate": "/api/v1/configure",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "ocelotgateway.api",
"Port": "80"
}
],
"UpstreamPathTemplate": "/configure",
"UpstreamHttpMethod": [ "POST" ]
},
{
"DownstreamPathTemplate": "/api/v1/hello",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "ocelotgateway.api",
"Port": "80"
}
],
"UpstreamPathTemplate": "/hello",
"UpstreamHttpMethod": [ "GET" ]
},
//RedisInterface API
{
"DownstreamPathTemplate": "/api/v1/{all}",
Expand Down