mirror of
https://github.com/gotson/komga.git
synced 2026-04-16 12:01:09 +02:00
fix: send proper JSON on API 404 instead of index.html
bug introduced in bb183828a1
This commit is contained in:
parent
ad07c4bb91
commit
fb147a447a
2 changed files with 26 additions and 17 deletions
|
|
@ -1,15 +1,14 @@
|
||||||
package org.gotson.komga.infrastructure.web
|
package org.gotson.komga.infrastructure.web
|
||||||
|
|
||||||
import org.springframework.boot.web.server.ErrorPage
|
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer
|
|
||||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory
|
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.http.CacheControl
|
import org.springframework.http.CacheControl
|
||||||
import org.springframework.http.HttpStatus
|
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||||
|
import org.springframework.web.servlet.NoHandlerFoundException
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
@ -25,18 +24,29 @@ class StaticResourceConfiguration : WebMvcConfigurer {
|
||||||
"classpath:public/favicon.ico"
|
"classpath:public/favicon.ico"
|
||||||
)
|
)
|
||||||
.setCacheControl(CacheControl.noStore())
|
.setCacheControl(CacheControl.noStore())
|
||||||
}
|
|
||||||
|
|
||||||
override fun addViewControllers(registry: ViewControllerRegistry) {
|
registry
|
||||||
registry.addViewController("/notFound")
|
.addResourceHandler(
|
||||||
.setStatusCode(HttpStatus.OK)
|
"/css/**",
|
||||||
.setViewName("forward:/")
|
"/fonts/**",
|
||||||
|
"/img/**",
|
||||||
|
"/js/**"
|
||||||
|
)
|
||||||
|
.addResourceLocations(
|
||||||
|
"classpath:public/css/",
|
||||||
|
"classpath:public/fonts/",
|
||||||
|
"classpath:public/img/",
|
||||||
|
"classpath:public/js/"
|
||||||
|
)
|
||||||
|
.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS).cachePublic())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class CustomContainer : WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
|
@ControllerAdvice
|
||||||
override fun customize(factory: ConfigurableServletWebServerFactory) {
|
class Customizer {
|
||||||
factory.addErrorPages(ErrorPage(HttpStatus.NOT_FOUND, "/notFound"))
|
@ExceptionHandler(NoHandlerFoundException::class)
|
||||||
|
fun notFound(): String {
|
||||||
|
return "forward:/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ spring:
|
||||||
console:
|
console:
|
||||||
enabled: true
|
enabled: true
|
||||||
resources:
|
resources:
|
||||||
cache:
|
add-mappings: false
|
||||||
cachecontrol:
|
|
||||||
cache-public: true
|
|
||||||
max-age: 365d
|
|
||||||
jpa.properties:
|
jpa.properties:
|
||||||
javax:
|
javax:
|
||||||
persistence.sharedCache.mode: ENABLE_SELECTIVE
|
persistence.sharedCache.mode: ENABLE_SELECTIVE
|
||||||
|
|
@ -24,6 +21,8 @@ spring:
|
||||||
region.factory_class: org.hibernate.cache.jcache.JCacheRegionFactory
|
region.factory_class: org.hibernate.cache.jcache.JCacheRegionFactory
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
prefix: classpath:/public/
|
prefix: classpath:/public/
|
||||||
|
mvc:
|
||||||
|
throw-exception-if-no-handler-found: true
|
||||||
server.servlet.session.timeout: 7d
|
server.servlet.session.timeout: 7d
|
||||||
|
|
||||||
management:
|
management:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue