mirror of
https://github.com/gotson/komga.git
synced 2026-04-22 15:00:59 +02:00
refactor: relocate ResourceNotFoundController
This commit is contained in:
parent
de6c17a7f9
commit
2d404d3197
3 changed files with 22 additions and 20 deletions
|
|
@ -1,15 +1,8 @@
|
|||
package org.gotson.komga.infrastructure.web
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.http.CacheControl
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import org.springframework.web.servlet.NoHandlerFoundException
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
|
|
@ -90,15 +83,3 @@ class WebMvcConfiguration : WebMvcConfigurer {
|
|||
resolvers.add(DelimitedPairHandlerMethodArgumentResolver())
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
@ControllerAdvice
|
||||
class ResourceNotFoundController {
|
||||
val apis = listOf("/api", "/opds", "/sse")
|
||||
|
||||
@ExceptionHandler(NoHandlerFoundException::class)
|
||||
fun notFound(request: HttpServletRequest): String {
|
||||
if (apis.any { request.requestURI.startsWith(it, true) }) throw ResponseStatusException(HttpStatus.NOT_FOUND)
|
||||
return "forward:/"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package org.gotson.komga.interfaces.mvc
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import org.springframework.web.servlet.NoHandlerFoundException
|
||||
|
||||
@Component
|
||||
@ControllerAdvice
|
||||
class ResourceNotFoundController {
|
||||
val apis = listOf("/api", "/opds", "/sse")
|
||||
|
||||
@ExceptionHandler(NoHandlerFoundException::class)
|
||||
fun notFound(request: HttpServletRequest): String {
|
||||
if (apis.any { request.requestURI.startsWith(it, true) }) throw ResponseStatusException(HttpStatus.NOT_FOUND)
|
||||
return "forward:/"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.gotson.komga.infrastructure.web
|
||||
package org.gotson.komga.interfaces.mvc
|
||||
|
||||
import org.gotson.komga.interfaces.api.rest.WithMockCustomUser
|
||||
import org.junit.jupiter.api.Test
|
||||
Loading…
Reference in a new issue