mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
17.56.2021 812f12a69468d5b20fef7afc6cd82c130481e9ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package de.micromata.borgbutler.server
 
import mu.KotlinLogging
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.ViewResolver
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.EnableWebMvc
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.view.InternalResourceViewResolver
 
 
private val log = KotlinLogging.logger {}
 
@Configuration
@EnableWebMvc
open class WebConfig : WebMvcConfigurer {
    @Bean
    open fun internalResourceViewResolver(): ViewResolver {
        val bean = InternalResourceViewResolver()
        if (RunningMode.webBundled()) {
            bean.setPrefix("/web/")
        } else {
            bean.setPrefix("borgbutler-webapp/build/")
        }
        bean.setSuffix(".html")
        return bean
    }
 
    override fun addCorsMappings(registry: CorsRegistry) {
        if (RunningMode.webDevelopment) {
            log.warn("*********************************")
            log.warn("***********            **********")
            log.warn("*********** ATTENTION! **********")
            log.warn("***********            **********")
            log.warn("*********** Running in **********")
            log.warn("*********** dev mode!  **********")
            log.warn("***********            **********")
            log.warn("*********************************")
            log.warn("Don't deliver this app in dev mode due to security reasons (CrossOriginFilter is set)!")
            registry.addMapping("/**")
        }
    }
}