22
33import jakarta .servlet .http .HttpServletRequest ;
44import jakarta .servlet .http .HttpServletResponse ;
5+ import lombok .SneakyThrows ;
56import lombok .extern .slf4j .Slf4j ;
67import org .springframework .core .io .ClassPathResource ;
7- import org .springframework .http .MediaType ;
8+ import org .springframework .http .ResponseEntity ;
89import org .springframework .stereotype .Controller ;
910import org .springframework .util .FileCopyUtils ;
1011import org .springframework .web .bind .annotation .GetMapping ;
@@ -34,23 +35,18 @@ public String handleSearch(HttpServletRequest request, HttpServletResponse respo
3435 return renderFileData (relativePath , response );
3536 }
3637
37- @ GetMapping ({"/ui/docs/*.data" , "/ui/*.data" })
38- @ ResponseBody
39- public String handleDataFile (HttpServletRequest request , HttpServletResponse response ) throws IOException {
40- String fullPath = request .getRequestURI ().replace (request .getContextPath (), "" );
41- String relativePath = fullPath .substring (4 );
42- return renderFileData (relativePath , response );
43- }
44-
45-
4638 @ GetMapping ("/ui/**" )
47- public String handleHtmlView (HttpServletRequest request ) {
39+ @ SneakyThrows
40+ public Object handleView (HttpServletRequest request , HttpServletResponse response ) {
4841 String fullPath = request .getRequestURI ().replace (request .getContextPath (), "" );
4942 if ("/ui" .equals (fullPath ) || "/ui/" .equals (fullPath )) {
5043 return "index" ;
5144 }
52- String viewPath = fullPath .substring (4 );
53- return viewPath + "/index" ;
45+ String docPath = fullPath .substring (4 );
46+ if (docPath .endsWith (".data" )) {
47+ return ResponseEntity .ok (renderFileData (docPath , response ));
48+ }
49+ return docPath + "/index" ;
5450 }
5551
5652 private String renderFileData (String relativePath , HttpServletResponse response ) {
@@ -61,8 +57,6 @@ private String renderFileData(String relativePath, HttpServletResponse response)
6157 response .setStatus (HttpServletResponse .SC_NOT_FOUND );
6258 return "File not found: " + relativePath ;
6359 }
64- response .setContentType (MediaType .TEXT_PLAIN_VALUE );
65- response .setCharacterEncoding ("UTF-8" );
6660 InputStreamReader reader = new InputStreamReader (
6761 resource .getInputStream (),
6862 StandardCharsets .UTF_8
0 commit comments