Skip to content

Commit

Permalink
Check that webpack actually works when checking connection (#11960)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- authored Oct 1, 2021
1 parent f404a1b commit e27b646
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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);

Expand All @@ -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));
Expand All @@ -614,7 +615,7 @@ private void doStartDevModeServer(ApplicationConfiguration config)
}
port = getRunningDevServerPort(npmFolder);
if (port > 0) {
if (checkWebpackConnection()) {
if (checkConnection()) {
reuseExistingPort(port);
return;
} else {
Expand Down

0 comments on commit e27b646

Please sign in to comment.