🚧 Fixed bug
This commit is contained in:
parent
470516d5da
commit
ae668774fa
@ -16,6 +16,8 @@ import jakarta.ws.rs.core.Context;
|
|||||||
import jakarta.ws.rs.core.Link;
|
import jakarta.ws.rs.core.Link;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.Strings;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ public class ProxyResource
|
|||||||
@Route(path = "/*", order = 1)
|
@Route(path = "/*", order = 1)
|
||||||
public void proxy(@Context RoutingContext context)
|
public void proxy(@Context RoutingContext context)
|
||||||
{
|
{
|
||||||
List<String> requestSegments = List.of(context.request().path().split("/"));
|
List<String> requestSegments = Arrays.stream(context.request().path().split("/")).filter(item -> !StringUtils.isBlank(item)).toList();
|
||||||
|
|
||||||
Optional<ProxyRoute> routeOptional = routeService.match(requestSegments);
|
Optional<ProxyRoute> routeOptional = routeService.match(requestSegments);
|
||||||
if (routeOptional.isPresent())
|
if (routeOptional.isPresent())
|
||||||
@ -62,7 +64,7 @@ public class ProxyResource
|
|||||||
LOG.info("Matched route with target '{}'", route.target());
|
LOG.info("Matched route with target '{}'", route.target());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpResponse<byte[]> response = forward(context.request().method(), extractSession(context.request().cookies()), route.target(), concat(dropRoute(route.segments(), requestSegments)));
|
HttpResponse<byte[]> response = forward(context.request().method(), route.strategy(), extractSession(context.request().cookies()), route.target(), concat(dropRoute(route.segments(), requestSegments)));
|
||||||
ResponseHandler.success(context, response);
|
ResponseHandler.success(context, response);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -78,10 +80,10 @@ public class ProxyResource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse<byte[]> forward(HttpMethod method, String auth, String forwardRoot, String forwardPath) throws IOException, InterruptedException
|
public HttpResponse<byte[]> forward(HttpMethod method, String strategy, String auth, String forwardRoot, String forwardPath) throws IOException, InterruptedException
|
||||||
{
|
{
|
||||||
HttpRequest.Builder builder = HttpRequest.newBuilder().method(method.name(), HttpRequest.BodyPublishers.noBody()).uri(URI.create(forwardRoot + "/" + forwardPath));
|
HttpRequest.Builder builder = HttpRequest.newBuilder().method(method.name(), HttpRequest.BodyPublishers.noBody()).uri(URI.create(forwardRoot + "/" + forwardPath));
|
||||||
if (auth != null)
|
if (auth != null && Strings.CI.equals("OIDC", strategy))
|
||||||
{
|
{
|
||||||
builder.header("Authorization", String.format("Bearer %s", sessionRepository.get(auth)));
|
builder.header("Authorization", String.format("Bearer %s", sessionRepository.get(auth)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
routes:
|
routes:
|
||||||
- path: /api
|
- path: /api
|
||||||
target: http://localhost:8089/api/iam-backend
|
target: http://backend
|
||||||
strategy: NONE
|
strategy: NONE
|
||||||
- path: /
|
- path: /
|
||||||
target: http://localhost:8081
|
target: http://example.com
|
||||||
strategy: NONE
|
strategy: NONE
|
||||||
Loading…
x
Reference in New Issue
Block a user