|
17 | 17 | package org.joinfaces.docs.server.controller; |
18 | 18 |
|
19 | 19 | import jakarta.annotation.PostConstruct; |
20 | | -import jakarta.servlet.http.HttpServletRequest; |
21 | 20 | import lombok.extern.slf4j.Slf4j; |
22 | 21 | import org.joinfaces.docs.server.DocsServerProperties; |
23 | 22 | import org.joinfaces.docs.server.model.EntryInfo; |
|
28 | 27 | import org.springframework.stereotype.Controller; |
29 | 28 | import org.springframework.util.Assert; |
30 | 29 | import org.springframework.web.bind.annotation.GetMapping; |
| 30 | +import org.springframework.web.bind.annotation.PathVariable; |
31 | 31 | import org.springframework.web.context.request.WebRequest; |
32 | 32 | import org.springframework.web.server.ResponseStatusException; |
33 | | -import org.springframework.web.servlet.HandlerMapping; |
34 | 33 | import org.springframework.web.servlet.ModelAndView; |
35 | 34 | import org.springframework.web.servlet.view.RedirectView; |
36 | 35 |
|
@@ -72,20 +71,18 @@ void init() throws IOException { |
72 | 71 | .cachePublic(); |
73 | 72 | } |
74 | 73 |
|
75 | | - @GetMapping("/**") |
76 | | - public Object process(HttpServletRequest request, WebRequest webRequest) throws IOException { |
77 | | - String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); |
78 | | - |
| 74 | + @GetMapping("/{*path}") |
| 75 | + public Object process(@PathVariable String path, WebRequest webRequest) throws IOException { |
79 | 76 | File file = new File(baseDirPath, path); |
80 | 77 |
|
81 | | - if (!file.exists()) { |
82 | | - throw new ResponseStatusException(HttpStatus.NOT_FOUND); |
83 | | - } |
84 | | - |
85 | 78 | if (!file.getCanonicalPath().startsWith(baseDirPath)) { |
86 | 79 | return ResponseEntity.badRequest().build(); |
87 | 80 | } |
88 | 81 |
|
| 82 | + if (!file.exists()) { |
| 83 | + throw new ResponseStatusException(HttpStatus.NOT_FOUND); |
| 84 | + } |
| 85 | + |
89 | 86 | if (file.isFile()) { |
90 | 87 | return fileResponse(webRequest, file); |
91 | 88 | } |
|
0 commit comments