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
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
Addted transforms to route the request to the specific endpoint
  • Loading branch information
Artonus committed Jun 23, 2023
commit 14f2faacb86b65057b78a19f18468206d7e1991b
15 changes: 7 additions & 8 deletions src/OcelotGateway/Controllers/RouteController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Yarp.ReverseProxy.Configuration;
using Yarp.ReverseProxy.Transforms;

namespace Middleware.OcelotGateway.Controllers;

Expand All @@ -9,11 +10,6 @@ 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)
Expand Down Expand Up @@ -42,10 +38,10 @@ public IActionResult CreateDynamicRoute()
ClusterId = "testCluster",
Destinations = new Dictionary<string, DestinationConfig>
{
{ "testdest1", new DestinationConfig { Address = "http://taskplanner.api/api/v1/test" } }
{ "testdest1", new DestinationConfig { Address = "http://taskplanner.api/api/v1/test/hello" } }
}
};
var routecfg = new RouteConfig
var routeCfg = new RouteConfig
{
RouteId = "test",
Match = new()
Expand All @@ -54,8 +50,11 @@ public IActionResult CreateDynamicRoute()
},
ClusterId = "testCluster" //
};
// transforms allow us to change the path that is requested like below to replace direct forwarding
routeCfg = routeCfg.WithTransformPathSet("/");

clusterList.Add(clusterCfg);
routeList.Add(routecfg);
routeList.Add(routeCfg);

_inMemoryConfigProvider.Update(routeList, clusterList);

Expand Down