diff --git a/src/main/java/org/kabir/quarkus/ui/SampleServlet.java b/src/main/java/org/kabir/quarkus/ui/SampleServlet.java index f31e509..9015540 100644 --- a/src/main/java/org/kabir/quarkus/ui/SampleServlet.java +++ b/src/main/java/org/kabir/quarkus/ui/SampleServlet.java @@ -1,6 +1,7 @@ package org.kabir.quarkus.ui; import java.io.IOException; +import java.net.Socket; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; @@ -23,9 +24,23 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se } else if (path.equals("/callback")) { // Redirect back to a path controlled by the Angular client String redirectPath = "/clientCallback"; + + boolean proxy = Boolean.getBoolean("ui.proxy"); + if (proxy && checkProxyIsRunning()) { + redirectPath = "http://localhost:4200" + redirectPath; + } resp.sendRedirect(redirectPath); } else { resp.sendError(404); } } -} \ No newline at end of file + + private boolean checkProxyIsRunning() { + try (Socket s = new Socket("localhost", 4200)) { + return true; + } catch (IOException e) { + return false; + } + } +} + diff --git a/webapp/src/app/app.component.ts b/webapp/src/app/app.component.ts index 11136df..3cbc2e1 100644 --- a/webapp/src/app/app.component.ts +++ b/webapp/src/app/app.component.ts @@ -23,11 +23,19 @@ export class AppComponent { In default component. Other | Rest | - External + External `, styles: [] }) export class DefaultComponent { + externalUrl = '/servlet/make-external-call'; + + constructor() { + if (window.location.port === "4200") { + this.externalUrl = "http://localhost:8080" + this.externalUrl; + } + } + } @Component({