livereload: doesn't work when context path is set fix
@@ -210,6 +210,7 @@ import com.typesafe.config.Config;
import org.jooby.Env;
import org.jooby.Jooby.Module;
import org.jooby.MediaType;
+import org.jooby.Request;
import org.jooby.Route;
import org.jooby.Router;
import org.jooby.WebSocket;
@@ -368,8 +369,7 @@ public class LiveReload implements Module {
+ "/livereload.js";
router.assets("/livereload.js", livereloadjs);
/** {{liveReload}} local variable */
- router.use("*", (req, rsp) -> req.set("liveReload",
- "<script src=\"" + req.contextPath() + "/livereload.js\"></script>"))
+ router.use("*", (req, rsp) -> req.set("liveReload", template(req)))
.name("livereload");
String serverName = CaseFormat.LOWER_CAMEL
@@ -453,6 +453,17 @@ public class LiveReload implements Module {
}
}
+ private String template(Request req) {
+ String contextPath = req.contextPath();
+ return "<script>"
+ + "window.LiveReloadOptions = {"
+ + "host: '" + req.hostname() + "',"
+ + "port: '" + req.port() + contextPath + "'"
+ + "};"
+ + "</script>\n"
+ + "<script src=\"" + contextPath + "/livereload.js\"></script>";
+ }
+
private boolean isHello(final Map<String, Object> message) {
return "hello".equals(message.get("command"));
}
