Skip to content

Commit

Permalink
More robust port check for vite dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Dec 6, 2024
1 parent f9b2f67 commit 167a0dd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/am/ik/blog/admin/web/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public ResponseEntity<Void> login(@RequestParam(name = "redirect_path") String r
}
UriComponents uriComponents = uriComponentsBuilder.path(redirectPath).build();
String location;
if (referer.getPort() == VITE_DEV_PORT) {
int port = referer.getPort();
if (isViteDevPort(port)) {
// behind the vite proxy in the dev-mode
location = UriComponentsBuilder.fromUriString(uriComponents.toUriString())
.port(referer.getPort())
.toUriString();
location = UriComponentsBuilder.fromUriString(uriComponents.toUriString()).port(port).toUriString();
}
else {
location = uriComponents.toUriString();
Expand Down Expand Up @@ -91,4 +90,8 @@ public void deleteComment(@PathVariable Long commentId) {
public record CommentUpdateRequest(Comment.Status status) {
}

static boolean isViteDevPort(int port) {
return port >= 5170 && port <= 5179;
}

}

0 comments on commit 167a0dd

Please sign in to comment.