diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java index 8815d498..ed872726 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/ForwardedDevProcessor.java @@ -29,6 +29,7 @@ import org.jboss.logging.Logger; import io.quarkiverse.quinoa.QuinoaDevProxyHandlerConfig; +import io.quarkiverse.quinoa.QuinoaNetworkConfiguration; import io.quarkiverse.quinoa.QuinoaRecorder; import io.quarkiverse.quinoa.deployment.config.DevServerConfig; import io.quarkiverse.quinoa.deployment.config.QuinoaConfig; @@ -42,7 +43,6 @@ import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.DevServicesResultBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.LiveReloadBuildItem; import io.quarkus.deployment.console.ConsoleInstalledBuildItem; import io.quarkus.deployment.logging.LoggingSetupBuildItem; @@ -62,7 +62,6 @@ public class ForwardedDevProcessor { @BuildStep(onlyIf = IsDevelopment.class) public ForwardedDevServerBuildItem prepareDevService( - LaunchModeBuildItem launchMode, ConfiguredQuinoaBuildItem configuredQuinoa, InstalledPackageManagerBuildItem installedPackageManager, QuinoaConfig userConfig, @@ -78,9 +77,8 @@ public ForwardedDevServerBuildItem prepareDevService( final QuinoaConfig resolvedConfig = configuredQuinoa.resolvedConfig(); final DevServerConfig devServerConfig = resolvedConfig.devServer(); liveReload.setContextObject(QuinoaConfig.class, resolvedConfig); - final String configuredDevServerHost = devServerConfig.host(); - final boolean configuredTls = devServerConfig.tls(); - final boolean configuredTlsAllowInsecure = devServerConfig.tlsAllowInsecure(); + final QuinoaNetworkConfiguration networkConfiguration = new QuinoaNetworkConfiguration(devServerConfig.tls(), + devServerConfig.tlsAllowInsecure(), devServerConfig.host(), devServerConfig.port().orElse(0), false); final PackageManagerRunner packageManagerRunner = installedPackageManager.getPackageManager(); final String checkPath = resolvedConfig.devServer().checkPath().orElse(null); if (devService != null) { @@ -94,13 +92,10 @@ public ForwardedDevServerBuildItem prepareDevService( } LOG.debug("Quinoa config did not change; no need to restart."); devServices.produce(devService.toBuildItem()); - final String resolvedDevServerHost = PackageManagerRunner.isDevServerUp(devServerConfig.tls(), - devServerConfig.tlsAllowInsecure(), - devServerConfig.host(), - devServerConfig.port().get(), - checkPath); - return new ForwardedDevServerBuildItem(devServerConfig.tls(), devServerConfig.tlsAllowInsecure(), - resolvedDevServerHost, devServerConfig.port().get()); + networkConfiguration.setPort(devServerConfig.port().get()); + final String resolvedDevServerHost = PackageManagerRunner.isDevServerUp(networkConfiguration, checkPath); + networkConfiguration.setHost(resolvedDevServerHost); + return new ForwardedDevServerBuildItem(networkConfiguration); } shutdownDevService(); } @@ -119,14 +114,15 @@ public ForwardedDevServerBuildItem prepareDevService( return null; } final Integer port = devServerConfig.port().get(); + networkConfiguration.setPort(port); if (!devServerConfig.managed()) { // No need to start the dev-service it is not managed by Quinoa // We just check that it is up - final String resolvedHostIPAddress = PackageManagerRunner.isDevServerUp(configuredTls, configuredTlsAllowInsecure, - configuredDevServerHost, port, checkPath); + final String resolvedHostIPAddress = PackageManagerRunner.isDevServerUp(networkConfiguration, checkPath); if (resolvedHostIPAddress != null) { - return new ForwardedDevServerBuildItem(configuredTls, configuredTlsAllowInsecure, resolvedHostIPAddress, port); + networkConfiguration.setHost(resolvedHostIPAddress); + return new ForwardedDevServerBuildItem(networkConfiguration); } else { throw new IllegalStateException( "The Web UI dev server (configured as not managed by Quinoa) is not started on port: " + port); @@ -141,11 +137,8 @@ public ForwardedDevServerBuildItem prepareDevService( final AtomicReference dev = new AtomicReference<>(); PackageManagerRunner.DevServer devServer = null; try { - devServer = packageManagerRunner.dev(consoleInstalled, loggingSetup, configuredTls, configuredTlsAllowInsecure, - configuredDevServerHost, - port, - checkPath, - checkTimeout); + devServer = packageManagerRunner.dev(consoleInstalled, loggingSetup, networkConfiguration, + checkPath, checkTimeout); dev.set(devServer.process()); devServer.logCompressor().close(); final LiveCodingLogOutputFilter logOutputFilter = new LiveCodingLogOutputFilter( @@ -162,7 +155,8 @@ public ForwardedDevServerBuildItem prepareDevService( devService = new DevServicesResultBuildItem.RunningDevService( DEV_SERVICE_NAME, null, onClose, devServerConfigMap); devServices.produce(devService.toBuildItem()); - return new ForwardedDevServerBuildItem(configuredTls, configuredTlsAllowInsecure, devServer.hostIPAddress(), port); + networkConfiguration.setHost(devServer.hostIPAddress()); + return new ForwardedDevServerBuildItem(networkConfiguration); } catch (Throwable t) { packageManagerRunner.stopDev(dev.get()); if (devServer != null) { @@ -176,7 +170,7 @@ private static Map createDevServiceMapForDevUI(QuinoaConfig quin Map devServerConfigMap = new LinkedHashMap<>(); devServerConfigMap.put("quarkus.quinoa.dev-server.host", quinoaConfig.devServer().host()); devServerConfigMap.put("quarkus.quinoa.dev-server.port", - quinoaConfig.devServer().port().map(p -> p.toString()).orElse("")); + quinoaConfig.devServer().port().map(Object::toString).orElse("")); devServerConfigMap.put("quarkus.quinoa.dev-server.check-timeout", Integer.toString(quinoaConfig.devServer().checkTimeout())); devServerConfigMap.put("quarkus.quinoa.dev-server.check-path", quinoaConfig.devServer().checkPath().orElse("")); @@ -206,11 +200,12 @@ public void runtimeInit( } LOG.infof("Quinoa is forwarding unhandled requests to port: %d", devProxy.get().getPort()); final QuinoaDevProxyHandlerConfig handlerConfig = toDevProxyHandlerConfig(quinoaConfig, httpBuildTimeConfig); + final QuinoaNetworkConfiguration networkConfig = new QuinoaNetworkConfiguration(devProxy.get().isTls(), + devProxy.get().isTlsAllowInsecure(), devProxy.get().getHost(), + devProxy.get().getPort(), + quinoaConfig.devServer().websocket()); routes.produce(RouteBuildItem.builder().orderedRoute("/*", QUINOA_ROUTE_ORDER) - .handler(recorder.quinoaProxyDevHandler(handlerConfig, vertx.getVertx(), devProxy.get().isTls(), - devProxy.get().isTlsAllowInsecure(), devProxy.get().getHost(), - devProxy.get().getPort(), - quinoaConfig.devServer().websocket())) + .handler(recorder.quinoaProxyDevHandler(handlerConfig, vertx.getVertx(), networkConfig)) .build()); if (quinoaConfig.devServer().websocket()) { websocketSubProtocols.produce(new WebsocketSubProtocolsBuildItem("*")); diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java index a202cb3d..096f047a 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/items/ForwardedDevServerBuildItem.java @@ -1,34 +1,33 @@ package io.quarkiverse.quinoa.deployment.items; +import io.quarkiverse.quinoa.QuinoaNetworkConfiguration; import io.quarkus.builder.item.SimpleBuildItem; public final class ForwardedDevServerBuildItem extends SimpleBuildItem { - private final boolean tls; - private final boolean tlsAllowInsecure; - private final String host; - private final Integer port; + private final QuinoaNetworkConfiguration networkConfiguration; - public ForwardedDevServerBuildItem(boolean tls, boolean tlsAllowInsecure, String host, Integer port) { - this.tls = tls; - this.tlsAllowInsecure = tlsAllowInsecure; - this.host = host; - this.port = port; + public ForwardedDevServerBuildItem(QuinoaNetworkConfiguration networkConfiguration) { + this.networkConfiguration = networkConfiguration; + } + + public QuinoaNetworkConfiguration getNetworkConfiguration() { + return networkConfiguration; } public boolean isTls() { - return tls; + return networkConfiguration.isTls(); } public boolean isTlsAllowInsecure() { - return tlsAllowInsecure; + return networkConfiguration.isTlsAllowInsecure(); } public String getHost() { - return host; + return networkConfiguration.getHost(); } public Integer getPort() { - return port; + return networkConfiguration.getPort(); } -} +} \ No newline at end of file diff --git a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/packagemanager/PackageManagerRunner.java b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/packagemanager/PackageManagerRunner.java index 152d1b8a..e8fd3d57 100644 --- a/deployment/src/main/java/io/quarkiverse/quinoa/deployment/packagemanager/PackageManagerRunner.java +++ b/deployment/src/main/java/io/quarkiverse/quinoa/deployment/packagemanager/PackageManagerRunner.java @@ -27,6 +27,7 @@ import org.jboss.logging.Logger; +import io.quarkiverse.quinoa.QuinoaNetworkConfiguration; import io.quarkiverse.quinoa.deployment.SslUtil; import io.quarkiverse.quinoa.deployment.config.PackageManagerCommandConfig; import io.quarkiverse.quinoa.deployment.packagemanager.types.PackageManager; @@ -139,7 +140,7 @@ private static void killDescendants(ProcessHandle process, boolean force) { } public DevServer dev(Optional consoleInstalled, LoggingSetupBuildItem loggingSetup, - boolean tls, boolean tlsAllowInsecure, String devServerHost, int devServerPort, String checkPath, + QuinoaNetworkConfiguration network, String checkPath, int checkTimeout) { final PackageManager.Command dev = packageManager.dev(); LOG.infof("Running Quinoa package manager live coding as a dev service: %s", dev.commandWithArguments); @@ -156,16 +157,16 @@ public void run() { }); if (checkPath == null) { LOG.infof("Quinoa is configured to continue without check if the live coding server is up"); - return new DevServer(p, devServerHost, logCompressor); + return new DevServer(p, network.getHost(), logCompressor); } String ipAddress = null; try { int i = 0; - while ((ipAddress = isDevServerUp(tls, tlsAllowInsecure, devServerHost, devServerPort, checkPath)) == null) { + while ((ipAddress = isDevServerUp(network, checkPath)) == null) { if (++i >= checkTimeout / 500) { stopDev(p); throw new RuntimeException( - "Quinoa package manager live coding port " + devServerPort + "Quinoa package manager live coding port " + network.getPort() + " is still not listening after the checkTimeout."); } Thread.sleep(500); @@ -275,22 +276,23 @@ public void run() { } } - public static String isDevServerUp(boolean tls, boolean tlsAllowInsecure, String host, int port, String path) { + public static String isDevServerUp(QuinoaNetworkConfiguration network, String path) { if (path == null) { - return host; + return network.getHost(); } final String normalizedPath = path.indexOf("/") == 0 ? path : "/" + path; try { - InetAddress[] addresses = InetAddress.getAllByName(host); + InetAddress[] addresses = InetAddress.getAllByName(network.getHost()); for (InetAddress address : addresses) { try { final String hostAddress = address.getHostAddress(); final String ipAddress = address instanceof Inet6Address ? "[" + hostAddress + "]" : hostAddress; - URL url = new URL(String.format("%s://%s:%d%s", tls ? "https" : "http", ipAddress, port, normalizedPath)); + URL url = new URL(String.format("%s://%s:%d%s", network.isTls() ? "https" : "http", ipAddress, + network.getPort(), normalizedPath)); HttpURLConnection connection; - if (tls) { + if (network.isTls()) { HttpsURLConnection httpsConnection = (HttpsURLConnection) url.openConnection(); - if (tlsAllowInsecure) { + if (network.isTlsAllowInsecure()) { httpsConnection.setSSLSocketFactory(SslUtil.createNonValidatingSslContext().getSocketFactory()); httpsConnection.setHostnameVerifier(new HostnameVerifier() { @Override diff --git a/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc b/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc index 2c81bbcf..96c8f2e2 100644 --- a/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc +++ b/docs/modules/ROOT/pages/includes/quarkus-quinoa.adoc @@ -519,70 +519,73 @@ endif::add-copy-button-to-env-var[] --|boolean |`true` -a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-tls]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-tls[quarkus.quinoa.dev-server.tls]` + +a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-port]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-port[quarkus.quinoa.dev-server.port]` [.description] -- -When set to true, Quinoa requests will be forwarded with tls enabled. +Port of the server to forward requests to. The dev server process (i.e npm start) is managed like a dev service by Quarkus. If the external server responds with a 404, it is ignored by Quinoa and processed like any other backend request. ifdef::add-copy-button-to-env-var[] -Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_TLS+++[] +Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_PORT+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] -Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_TLS+++` +Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_PORT+++` endif::add-copy-button-to-env-var[] ---|boolean -|`false` +--|int +|`framework detection or fallback to empty` -a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-tls-allow-insecure]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-tls-allow-insecure[quarkus.quinoa.dev-server.tls.allow-insecure]` + +a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-host]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-host[quarkus.quinoa.dev-server.host]` [.description] -- -When set to true, Quinoa will accept any certificate with any hostname. +Host of the server to forward requests to. ifdef::add-copy-button-to-env-var[] -Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_TLS_ALLOW_INSECURE+++[] +Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_HOST+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] -Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_TLS_ALLOW_INSECURE+++` +Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_HOST+++` endif::add-copy-button-to-env-var[] ---|boolean -|`false` +--|string +|`localhost` -a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-port]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-port[quarkus.quinoa.dev-server.port]` + +a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-tls]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-tls[quarkus.quinoa.dev-server.tls]` [.description] -- -Port of the server to forward requests to. The dev server process (i.e npm start) is managed like a dev service by Quarkus. If the external server responds with a 404, it is ignored by Quinoa and processed like any other backend request. +When set to true, Quinoa requests will be forwarded with tls enabled. ifdef::add-copy-button-to-env-var[] -Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_PORT+++[] +Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_TLS+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] -Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_PORT+++` +Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_TLS+++` endif::add-copy-button-to-env-var[] ---|int -|`framework detection or fallback to empty` +--|boolean +|`false` -a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-host]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-host[quarkus.quinoa.dev-server.host]` +a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-tls-allow-insecure]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-tls-allow-insecure[quarkus.quinoa.dev-server.tls-allow-insecure]` [.description] -- -Host of the server to forward requests to. +When set to true, Quinoa will accept any certificate with any hostname. ifdef::add-copy-button-to-env-var[] -Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_HOST+++[] +Environment variable: env_var_with_copy_button:+++QUARKUS_QUINOA_DEV_SERVER_TLS_ALLOW_INSECURE+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] -Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_HOST+++` +Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_TLS_ALLOW_INSECURE+++` endif::add-copy-button-to-env-var[] ---|string -|`localhost` +--|boolean +|`false` a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-check-path]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-check-path[quarkus.quinoa.dev-server.check-path]` @@ -667,7 +670,7 @@ ifndef::add-copy-button-to-env-var[] Environment variable: `+++QUARKUS_QUINOA_DEV_SERVER_INDEX_PAGE+++` endif::add-copy-button-to-env-var[] --|string -|`auto-detected falling back to the quinoa.index-page` +|`auto-detected falling back to index.html` a|icon:lock[title=Fixed at build time] [[quarkus-quinoa_quarkus-quinoa-dev-server-direct-forwarding]]`link:#quarkus-quinoa_quarkus-quinoa-dev-server-direct-forwarding[quarkus.quinoa.dev-server.direct-forwarding]` @@ -776,4 +779,4 @@ endif::add-copy-button-to-env-var[] | -|=== +|=== \ No newline at end of file diff --git a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java index 31065b1d..0cd1fba1 100644 --- a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java +++ b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevProxyHandler.java @@ -7,7 +7,6 @@ import java.util.List; -import io.vertx.ext.web.client.WebClientOptions; import org.jboss.logging.Logger; import io.vertx.core.AsyncResult; @@ -21,6 +20,7 @@ import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.WebClientOptions; class QuinoaDevProxyHandler implements Handler { private static final Logger LOG = Logger.getLogger(QuinoaDevProxyHandler.class); @@ -30,29 +30,21 @@ class QuinoaDevProxyHandler implements Handler { HttpHeaders.CONTENT_LENGTH.toString(), HttpHeaders.CONTENT_TYPE.toString()); - private final String host; - private final int port; + private final QuinoaNetworkConfiguration networkConfiguration; private final WebClient client; private final QuinoaDevWebSocketProxyHandler wsUpgradeHandler; private final ClassLoader currentClassLoader; private final QuinoaDevProxyHandlerConfig config; - QuinoaDevProxyHandler(final QuinoaDevProxyHandlerConfig config, final Vertx vertx, boolean tls, boolean tlsAllowInsecure, - String host, int port, - boolean websocket) { - this.host = host; - this.port = port; + QuinoaDevProxyHandler(final QuinoaDevProxyHandlerConfig config, final Vertx vertx, QuinoaNetworkConfiguration network) { WebClientOptions options = new WebClientOptions(); - if (tls) { - options.setSsl(true); - if (tlsAllowInsecure) { - options.setTrustAll(true); - options.setVerifyHost(false); - } - } + options.setSsl(network.isTls()); + options.setTrustAll(network.isTlsAllowInsecure()); + options.setVerifyHost(!network.isTlsAllowInsecure()); this.client = WebClient.create(vertx, options); - this.wsUpgradeHandler = websocket ? new QuinoaDevWebSocketProxyHandler(vertx, host, port) : null; + this.wsUpgradeHandler = network.isWebsocket() ? new QuinoaDevWebSocketProxyHandler(vertx, network) : null; this.config = config; + this.networkConfiguration = network; currentClassLoader = Thread.currentThread().getContextClassLoader(); } @@ -97,7 +89,7 @@ private void handleHttpRequest(final RoutingContext ctx, final String resourcePa // Disable compression in the forwarded request headers.remove("Accept-Encoding"); - client.request(request.method(), port, host, uri) + client.request(request.method(), networkConfiguration.getPort(), networkConfiguration.getHost(), uri) .putHeaders(headers) .send(event -> { if (event.succeeded()) { diff --git a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevWebSocketProxyHandler.java b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevWebSocketProxyHandler.java index b7a5c2e7..054970ed 100644 --- a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevWebSocketProxyHandler.java +++ b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaDevWebSocketProxyHandler.java @@ -18,13 +18,11 @@ class QuinoaDevWebSocketProxyHandler { private static final Logger LOG = Logger.getLogger(QuinoaDevWebSocketProxyHandler.class); private final HttpClient httpClient; - private String host; - private final int port; + private final QuinoaNetworkConfiguration networkConfiguration; - QuinoaDevWebSocketProxyHandler(Vertx vertx, String host, int port) { + QuinoaDevWebSocketProxyHandler(Vertx vertx, QuinoaNetworkConfiguration network) { this.httpClient = vertx.createHttpClient(); - this.host = host; - this.port = port; + this.networkConfiguration = network; } public void handle(final RoutingContext ctx) { @@ -33,7 +31,8 @@ public void handle(final RoutingContext ctx) { request.toWebSocket(r -> { if (r.succeeded()) { final String forwardUri = request.uri(); - LOG.debugf("Quinoa Dev WebSocket Server Connected: %s:%s%s", host, port, forwardUri); + LOG.debugf("Quinoa Dev WebSocket Server Connected: %s:%s%s", networkConfiguration.getHost(), + networkConfiguration.getPort(), forwardUri); final ServerWebSocket serverWs = r.result(); final AtomicReference clientWs = new AtomicReference<>(); serverWs @@ -58,8 +57,8 @@ public void handle(final RoutingContext ctx) { } final WebSocketConnectOptions options = new WebSocketConnectOptions() - .setHost(host) - .setPort(port) + .setHost(networkConfiguration.getHost()) + .setPort(networkConfiguration.getPort()) .setURI(forwardUri) .setHeaders(serverWs.headers()) .setSubProtocols(subProtocols) @@ -68,7 +67,8 @@ public void handle(final RoutingContext ctx) { httpClient.webSocket(options, clientContext -> { if (clientContext.succeeded()) { - LOG.infof("Quinoa Dev WebSocket Client Connected: %s:%s%s", host, port, forwardUri); + LOG.infof("Quinoa Dev WebSocket Client Connected: %s:%s%s", networkConfiguration.getHost(), + networkConfiguration.getPort(), forwardUri); clientWs.set(clientContext.result()); // messages from NodeJS forwarded back to browser clientWs.get().exceptionHandler( @@ -99,4 +99,4 @@ public void handle(final RoutingContext ctx) { }); } -} +} \ No newline at end of file diff --git a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaNetworkConfiguration.java b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaNetworkConfiguration.java new file mode 100644 index 00000000..89ddc8f0 --- /dev/null +++ b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaNetworkConfiguration.java @@ -0,0 +1,131 @@ +package io.quarkiverse.quinoa; + +import java.util.Objects; +import java.util.StringJoiner; + +/** + * Represents the network configuration settings for Quinoa, + * including TLS options, host, port, and websocket settings. + */ +public class QuinoaNetworkConfiguration { + + private final boolean tls; + private final boolean tlsAllowInsecure; + private String host; + private Integer port; + private final boolean websocket; + + /** + * Constructs a new {@code QuinoaNetworkConfiguration} with the specified settings. + * + * @param tls whether TLS is enabled + * @param tlsAllowInsecure whether insecure TLS connections are allowed + * @param host the hostname or IP address of the server + * @param port the port number on which the server is listening + * @param websocket whether websocket is enabled + */ + public QuinoaNetworkConfiguration(boolean tls, boolean tlsAllowInsecure, String host, Integer port, boolean websocket) { + this.tls = tls; + this.tlsAllowInsecure = tlsAllowInsecure; + this.host = host; + this.port = port; + this.websocket = websocket; + } + + /** + * Returns whether TLS is enabled. + * + * @return {@code true} if TLS is enabled, {@code false} otherwise + */ + public boolean isTls() { + return tls; + } + + /** + * Returns whether insecure TLS connections are allowed. + * + * @return {@code true} if insecure TLS connections are allowed, {@code false} otherwise + */ + public boolean isTlsAllowInsecure() { + return tlsAllowInsecure; + } + + /** + * Returns the hostname or IP address of the server. + * + * @return the host + */ + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + /** + * Returns the port number on which the server is listening. + * + * @return the port number + */ + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + /** + * Returns whether websocket is enabled. + * + * @return {@code true} if websocket is enabled, {@code false} otherwise + */ + public boolean isWebsocket() { + return websocket; + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param o the reference object with which to compare + * @return {@code true} if this object is the same as the obj argument; {@code false} otherwise + */ + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + QuinoaNetworkConfiguration that = (QuinoaNetworkConfiguration) o; + return isTls() == that.isTls() && isTlsAllowInsecure() == that.isTlsAllowInsecure() + && isWebsocket() == that.isWebsocket() && Objects.equals(getHost(), that.getHost()) + && Objects.equals(getPort(), that.getPort()); + } + + /** + * Returns a hash code value for the object. + * + * @return a hash code value for this object + */ + @Override + public int hashCode() { + return Objects.hash(isTls(), isTlsAllowInsecure(), getHost(), getPort(), isWebsocket()); + } + + /** + * Returns a string representation of the object. + * + * @return a string representation of the object + */ + @Override + public String toString() { + return new StringJoiner(", ", QuinoaNetworkConfiguration.class.getSimpleName() + "[", "]") + .add("tls=" + tls) + .add("tlsAllowInsecure=" + tlsAllowInsecure) + .add("host='" + host + "'") + .add("port=" + port) + .add("websocket=" + websocket) + .toString(); + } +} \ No newline at end of file diff --git a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java index 07cb3c9b..c11a2e11 100644 --- a/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java +++ b/runtime/src/main/java/io/quarkiverse/quinoa/QuinoaRecorder.java @@ -26,12 +26,12 @@ public class QuinoaRecorder { public static final Set HANDLED_METHODS = Set.of(HttpMethod.HEAD, HttpMethod.OPTIONS, HttpMethod.GET); public Handler quinoaProxyDevHandler(final QuinoaDevProxyHandlerConfig handlerConfig, Supplier vertx, - boolean tls, boolean tlsAllowInsecure, String host, int port, boolean websocket) { + QuinoaNetworkConfiguration network) { if (LOG.isDebugEnabled()) { LOG.debugf("Quinoa dev proxy-handler is ignoring paths starting with: " + String.join(", ", handlerConfig.ignoredPathPrefixes)); } - return new QuinoaDevProxyHandler(handlerConfig, vertx.get(), tls, tlsAllowInsecure, host, port, websocket); + return new QuinoaDevProxyHandler(handlerConfig, vertx.get(), network); } public Handler quinoaSPARoutingHandler(List ignoredPathPrefixes) throws IOException { @@ -85,4 +85,4 @@ static void next(ClassLoader cl, RoutingContext ctx) { ctx.next(); } -} +} \ No newline at end of file