Permalink
Find file Copy path
4556da1 Nov 7, 2017
1 contributor

Users who have contributed to this file

42 lines (39 sloc) 1.3 KB
package functional
import com.samskivert.mustache.Mustache
import functional.web.Routes
import functional.web.UserHandler
import functional.web.view.MustacheResourceTemplateLoader
import functional.web.view.MustacheViewResolver
import org.springframework.context.support.ReloadableResourceBundleMessageSource
import org.springframework.context.support.beans
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.reactive.CorsWebFilter
import org.springframework.web.reactive.function.server.HandlerStrategies
import org.springframework.web.reactive.function.server.RouterFunctions
fun beans() = beans {
bean<UserHandler>()
bean<Routes>()
bean("webHandler") {
RouterFunctions.toWebHandler(ref<Routes>().router(), HandlerStrategies.builder().viewResolver(ref()).build())
}
bean("messageSource") {
ReloadableResourceBundleMessageSource().apply {
setBasename("messages")
setDefaultEncoding("UTF-8")
}
}
bean {
val prefix = "classpath:/templates/"
val suffix = ".mustache"
val loader = MustacheResourceTemplateLoader(prefix, suffix)
MustacheViewResolver(Mustache.compiler().withLoader(loader)).apply {
setPrefix(prefix)
setSuffix(suffix)
}
}
profile("cors") {
bean("corsFilter") {
CorsWebFilter { CorsConfiguration().applyPermitDefaultValues() }
}
}
}