From a5f7c438d5b0bd74ebc774dda30e147b4428d1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=94=E6=88=88=E9=87=8C?= Date: Tue, 19 Jul 2022 10:36:05 +0800 Subject: [PATCH] perf: access to admin page changed to template rendering (#2259) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 访问后台管理时使用重定向,在有反向代理且配置不完善的情况下,会导致重定向的域名发生错误。 https://spring.io/guides/gs/serving-web-content/ #### Which issue(s) this PR fixes: Fixes #2254 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note 修改后台管理页面为直接渲染而不是重定向,以更好的兼容反向代理 ``` --- .../app/controller/content/MainController.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/run/halo/app/controller/content/MainController.java b/src/main/java/run/halo/app/controller/content/MainController.java index d2f6f58a4..9c31ef556 100644 --- a/src/main/java/run/halo/app/controller/content/MainController.java +++ b/src/main/java/run/halo/app/controller/content/MainController.java @@ -50,11 +50,9 @@ public class MainController { } @GetMapping("${halo.admin-path:admin}") - public void admin(HttpServletResponse response) throws IOException { - String adminIndexRedirectUri = - HaloUtils.ensureBoth(haloProperties.getAdminPath(), HaloUtils.URL_SEPARATOR) - + INDEX_REDIRECT_URI; - response.sendRedirect(adminIndexRedirectUri); + public String admin() throws IOException { + return HaloUtils.ensureBoth(haloProperties.getAdminPath(), HaloUtils.URL_SEPARATOR) + + INDEX_REDIRECT_URI; } @GetMapping("version") @@ -64,14 +62,12 @@ public class MainController { } @GetMapping("install") - public void installation(HttpServletResponse response) throws IOException { + public String installation() throws IOException { boolean isInstalled = optionService .getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false); if (!isInstalled) { - String installRedirectUri = - StringUtils.appendIfMissing(this.haloProperties.getAdminPath(), "/") - + INSTALL_REDIRECT_URI; - response.sendRedirect(installRedirectUri); + return StringUtils.appendIfMissing(this.haloProperties.getAdminPath(), "/") + + INSTALL_REDIRECT_URI; } else { throw new NotFoundException("404"); } @@ -103,4 +99,4 @@ public class MainController { response.sendRedirect(HaloUtils.normalizeUrl(favicon)); } } -} +} \ No newline at end of file