diff --git a/launchers/common/src/main/java/com/tencent/supersonic/web/ErrorPageConfig.java b/launchers/common/src/main/java/com/tencent/supersonic/web/ErrorPageConfig.java index ed25ff189..d95525906 100644 --- a/launchers/common/src/main/java/com/tencent/supersonic/web/ErrorPageConfig.java +++ b/launchers/common/src/main/java/com/tencent/supersonic/web/ErrorPageConfig.java @@ -1,18 +1,41 @@ package com.tencent.supersonic.web; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.boot.web.server.ErrorPage; import org.springframework.boot.web.server.ErrorPageRegistrar; import org.springframework.boot.web.server.ErrorPageRegistry; +import org.springframework.core.Ordered; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerExceptionResolver; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.resource.NoResourceFoundException; +import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; /** error page config */ @Component -public class ErrorPageConfig implements ErrorPageRegistrar { +public class ErrorPageConfig implements ErrorPageRegistrar, HandlerExceptionResolver, Ordered { @Override public void registerErrorPages(ErrorPageRegistry registry) { ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/webapp/index.html"); registry.addErrorPages(error404Page); } + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE; + } + + @Override + public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { + if (handler instanceof ResourceHttpRequestHandler && ex instanceof NoResourceFoundException) { + ModelAndView modelAndView = new ModelAndView("/webapp/index.html"); + response.setStatus(HttpStatus.OK.value()); + return modelAndView; + } + + return null; + } } diff --git a/launchers/common/src/main/java/com/tencent/supersonic/web/WebConfig.java b/launchers/common/src/main/java/com/tencent/supersonic/web/WebConfig.java index e14f93fde..f7a179215 100644 --- a/launchers/common/src/main/java/com/tencent/supersonic/web/WebConfig.java +++ b/launchers/common/src/main/java/com/tencent/supersonic/web/WebConfig.java @@ -12,10 +12,13 @@ public class WebConfig implements WebMvcConfigurer { public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/webapp/**") .addResourceLocations("classpath:/webapp/"); + + registry.addResourceHandler("/favicon.ico") + .addResourceLocations("classpath:/webapp/"); } @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("forward:webapp/index.html"); + registry.addViewController("/").setViewName("forward:/webapp/index.html"); } }