-DVERTXWEB_ENVIRONMENT=dev is no longer working

62 views
Skip to first unread message

RCoe

unread,
Mar 1, 2021, 7:58:22 PM3/1/21
to vert.x
I recall in 3.5 that the -DVERTXWEB_ENVIRONMENT=dev runtime parameter, to disable caching behaviour, allowed me to save static html and reload my browser to see the change.  I can no longer get this to work in 4.0.

I am using vsCode and building with maven.  When I save my source:
> src/resources/webroot/index.html

it gets copied automatically to:
> target/resources/webroot/index.html

However, my browser is not picking up the change without restarting my HTTP verticle.  I have confirmed that my browser (Edge) is not caching files when the developer pane is open.

The command that starts my verticles is created by the vsCode debug lens:
> /usr/bin/env /usr/lib/jvm/java-11-openjdk-amd64/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:44109 -Dvertx.disableDnsResolver=true -DVERTXWEB_ENVIRONMENT=dev -Dfile.encoding=UTF-8 @/tmp/cp_1nyqaeh6y4ers5nwp6cv6z9k6.argfile ca.linkedtutoring.chat.MainVerticle -conf /d/cygwin64/home/rcoe/linked/conf/config.json

Am I missing something obvious?

Thanks


GERARD Nicolas

unread,
Mar 2, 2021, 5:12:47 AM3/2/21
to vert.x
In master (4x), I can see still that it will react to this env.

Line:

That calls:

And that expects as env variabe:
VERTXWEB_ENVIRONMENT
but as system:
vertxweb.environment

Don't ask me why but this is what this is.

Try to change your command to:
-Dvertxweb.environment=dev

Cheers
Nico

Robin Coe

unread,
Mar 2, 2021, 5:03:06 PM3/2/21
to ve...@googlegroups.com

The linked code is for vertx3 but I used your idea to investigate the vertx 4 code.  Attached below is the method that is called when starting the vertical:

public interface WebEnvironment {

  String SYSTEM_PROPERTY_NAME = "vertxweb.environment";
  String ENV_VARIABLE_NAME = "VERTXWEB_ENVIRONMENT";

  /**
   * Will return true if the mode is not null and equals ignoring case the string "dev"
   * @return always boolean
   */
  static boolean development() {
    final String mode = mode();
    return "dev".equalsIgnoreCase(mode) || "Development".equalsIgnoreCase(mode);
  }

  /**
   * The current mode from the system properties with fallback to environment variables
   * @return String with mode value or null
   */
  static @Nullable String mode() {
    return System.getProperty(SYSTEM_PROPERTY_NAMESystem.getenv(ENV_VARIABLE_NAME));
  }
}

In the case of starting the JVM with -D, we're dealing with an environment variable not a system property, so it should be upper case.  And, in fact, putting a breakpoint on this line that checks the value of "mode" confirms that development() returns true.  So I was using the correct environment variable name,   But even though this method returns true, I still do not see my code changes picked up by the verticle handling my static resources:


        router.route().handlerStaticHandler.create() );


Strange thing is, I don't see a meta tag for cache behaviour in my rendered page:

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

I'd expect to see these tags added in dev mode, to disable browser caching:
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
But the browser cache behaviour isn't involved in this case.

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/MvN6CTpRvfw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/fa46c78e-9ddf-45f2-8c62-5077c2833598n%40googlegroups.com.

Paulo Lopes

unread,
Mar 3, 2021, 7:34:36 AM3/3/21
to vert.x
The web environment flag doesn't change template content. We could however on the static handler disable cache headers in dev mode. But this won't affect template generated content

Paulo Lopes

unread,
Mar 3, 2021, 7:37:17 AM3/3/21
to vert.x
After double-checking, this is in fact already like this:

/**
* Default of whether cache header handling is enabled
*/
boolean DEFAULT_CACHING_ENABLED = !WebEnvironment.development();

Robin Coe

unread,
Mar 4, 2021, 9:09:22 AM3/4/21
to ve...@googlegroups.com
Could be my expectations of hotspot behaviour, coming to vscode from Eclipse, in that hot-swapping code into the runtime avoids restarting the JVM.  Although vscode uses the same server, I'd think that would be accommodated.  As it is, I need to restart my vertices to pick up any code changes, server or client.

As far as the browser <meta> tags are concerned, I'd think template engines, in general, should match what JSPs use, regardless of dev mode.  In the case of dev mode, though, the meta tags should inform the browser to not cache static resources.

Reply all
Reply to author
Forward
0 new messages