From e27b646a10afc246356ef171e62634ee7770d595 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 1 Oct 2021 13:17:17 +0300 Subject: [PATCH] Check that webpack actually works when checking connection (#11960) --- .../vaadin/base/devserver/WebpackHandler.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/WebpackHandler.java b/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/WebpackHandler.java index 2c2c2c6f5da..94759c7aca1 100644 --- a/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/WebpackHandler.java +++ b/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/WebpackHandler.java @@ -386,10 +386,9 @@ public boolean serveDevModeRequest(HttpServletRequest request, return true; } - private boolean checkWebpackConnection() { + private boolean checkConnection() { try { - readManifestPaths(); - return true; + return readManifestPaths(); } catch (IOException e) { getLogger().debug("Error checking webpack dev server connection", e); @@ -550,9 +549,10 @@ private void runOnFutureComplete(ApplicationConfiguration config) { * Those paths do not necessarily start with /VAADIN, as some resources must * be served from the root directory, e. g., service worker JS. * + * @return true if reading succeeded, false otherwise * @throws IOException */ - private void readManifestPaths() throws IOException { + private boolean readManifestPaths() throws IOException { getLogger().debug("Reading manifest.json from webpack"); HttpURLConnection connection = prepareConnection("/manifest.json", "GET"); @@ -562,7 +562,7 @@ private void readManifestPaths() throws IOException { "Unable to get manifest.json from " + "webpack-dev-server, got {} {}", responseCode, connection.getResponseMessage()); - return; + return false; } String manifestJson = FrontendUtils @@ -573,6 +573,7 @@ private void readManifestPaths() throws IOException { "Got asset paths from webpack manifest.json: \n {}", String.join("\n ", manifestPaths)); } + return true; } private void saveRunningDevServerPort() { @@ -585,7 +586,7 @@ private void saveRunningDevServerPort() { } private boolean checkPort() { - if (checkWebpackConnection()) { + if (checkConnection()) { getLogger().info("Reusing webpack-dev-server running at {}:{}", WEBPACK_HOST, port); @@ -604,7 +605,7 @@ private void doStartDevModeServer(ApplicationConfiguration config) throws ExecutionFailedException { // If port is defined, means that webpack is already running if (port > 0) { - if (!checkWebpackConnection()) { + if (!checkConnection()) { throw new IllegalStateException(format( "%s webpack-dev-server port '%d' is defined but it's not working properly", START_FAILURE, port)); @@ -614,7 +615,7 @@ private void doStartDevModeServer(ApplicationConfiguration config) } port = getRunningDevServerPort(npmFolder); if (port > 0) { - if (checkWebpackConnection()) { + if (checkConnection()) { reuseExistingPort(port); return; } else {