Skip to content

Commit

Permalink
Merge pull request quarkusio#44840 from albers/remote-dev-contextpath
Browse files Browse the repository at this point in the history
Remote development mode can be used on deployments with context path
  • Loading branch information
geoand authored Dec 3, 2024
2 parents 0e3208d + 0664069 commit 57f0e20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public static void startServerAfterFailedStart() {
if (liveReloadConfig.password().isPresent()
&& hotReplacementContext.getDevModeType() == DevModeType.REMOTE_SERVER_SIDE) {
root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password().get(), root,
hotReplacementContext);
hotReplacementContext, "/");
}
rootHandler = root;

Expand Down Expand Up @@ -547,7 +547,8 @@ public void handle(RoutingContext event) {
}
if (launchMode == LaunchMode.DEVELOPMENT && liveReloadConfig.password().isPresent()
&& hotReplacementContext.getDevModeType() == DevModeType.REMOTE_SERVER_SIDE) {
root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password().get(), root, hotReplacementContext);
root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password().get(), root, hotReplacementContext,
rootPath);
}
rootHandler = root;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class RemoteSyncHandler implements Handler<HttpServerRequest> {
final String password;
final Handler<HttpServerRequest> next;
final HotReplacementContext hotReplacementContext;
final String rootPath;

//all these are static to allow the handler to be recreated on hot reload
//which makes lifecycle management a lot easier
Expand All @@ -48,10 +49,12 @@ public class RemoteSyncHandler implements Handler<HttpServerRequest> {
static volatile Throwable remoteProblem;
static volatile boolean checkForChanges;

public RemoteSyncHandler(String password, Handler<HttpServerRequest> next, HotReplacementContext hotReplacementContext) {
public RemoteSyncHandler(String password, Handler<HttpServerRequest> next, HotReplacementContext hotReplacementContext,
String rootPath) {
this.password = password;
this.next = next;
this.hotReplacementContext = hotReplacementContext;
this.rootPath = rootPath;
}

public static void doPreScan() {
Expand Down Expand Up @@ -98,11 +101,11 @@ private void handleRequest(HttpServerRequest event) {
} else if (event.method().equals(HttpMethod.DELETE)) {
handleDelete(event);
} else if (event.method().equals(HttpMethod.POST)) {
if (event.path().equals(DEV)) {
if (event.path().endsWith(DEV)) {
handleDev(event);
} else if (event.path().equals(CONNECT)) {
} else if (event.path().endsWith(CONNECT)) {
handleConnect(event);
} else if (event.path().equals(PROBE)) {
} else if (event.path().endsWith(PROBE)) {
event.response().end();
} else {
event.response().putHeader(QUARKUS_ERROR, "Unknown path " + event.path()
Expand Down Expand Up @@ -220,7 +223,8 @@ public void handle(Buffer buffer) {
return;
}
try {
hotReplacementContext.updateFile(event.path(), buffer.getBytes());
String path = stripRootPath(event.path());
hotReplacementContext.updateFile(path, buffer.getBytes());
} catch (Exception e) {
log.error("Failed to update file", e);
}
Expand All @@ -236,6 +240,12 @@ public void handle(Throwable error) {
}).resume();
}

private String stripRootPath(String path) {
return path.startsWith(rootPath)
? path.substring(rootPath.length())
: path;
}

private void handleDelete(HttpServerRequest event) {
if (checkSession(event, event.path().getBytes(StandardCharsets.UTF_8)))
return;
Expand Down

0 comments on commit 57f0e20

Please sign in to comment.