From 167a0dd284e465d52ae1c5af786b39d5c6d2e165 Mon Sep 17 00:00:00 2001 From: Toshiaki Maki Date: Fri, 6 Dec 2024 09:13:54 +0900 Subject: [PATCH] More robust port check for vite dev mode --- .../java/am/ik/blog/admin/web/AdminController.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/am/ik/blog/admin/web/AdminController.java b/src/main/java/am/ik/blog/admin/web/AdminController.java index c1c0a69..b7efd90 100644 --- a/src/main/java/am/ik/blog/admin/web/AdminController.java +++ b/src/main/java/am/ik/blog/admin/web/AdminController.java @@ -54,11 +54,10 @@ public ResponseEntity 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(); @@ -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; + } + }