mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-04-26 19:36:55 -05:00
Fixes issues with embed calendar links due to changing to webflux
This commit is contained in:
@@ -9,6 +9,8 @@ services:
|
||||
MYSQL_DATABASE: discal
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- ./.docker/data/mysql:/var/lib/mysql
|
||||
|
||||
redis:
|
||||
image: redis:6.0.10
|
||||
|
||||
@@ -14,27 +14,21 @@ import org.springframework.data.redis.connection.RedisPassword
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.web.reactive.config.CorsRegistry
|
||||
import org.springframework.web.cors.CorsConfiguration
|
||||
import org.springframework.web.cors.reactive.CorsWebFilter
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource
|
||||
import org.springframework.web.reactive.config.EnableWebFlux
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer
|
||||
|
||||
@Configuration
|
||||
@EnableWebFlux
|
||||
@EnableAutoConfiguration
|
||||
class WebFluxConfig : WebFluxConfigurer, WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
|
||||
class WebFluxConfig : WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
|
||||
|
||||
override fun customize(factory: ConfigurableWebServerFactory?) {
|
||||
factory?.setPort(BotSettings.PORT.get().toInt())
|
||||
factory?.addErrorPages(ErrorPage(HttpStatus.NOT_FOUND, "/"))
|
||||
}
|
||||
|
||||
override fun addCorsMappings(registry: CorsRegistry) {
|
||||
registry.addMapping("/api/**")
|
||||
.allowedOrigins("*")
|
||||
registry.addMapping("/v2/**")
|
||||
.allowedOrigins("*")
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun redisConnectionFactory(): LettuceConnectionFactory {
|
||||
val rsc = RedisStandaloneConfiguration()
|
||||
@@ -72,4 +66,21 @@ class WebFluxConfig : WebFluxConfigurer, WebServerFactoryCustomizer<Configurable
|
||||
.option(ConnectionFactoryOptions.SSL, false)
|
||||
.build())
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun corsWebFilter(): CorsWebFilter {
|
||||
val config = CorsConfiguration()
|
||||
|
||||
config.maxAge = 8000L
|
||||
config.addAllowedOrigin("*")
|
||||
config.addAllowedMethod("GET")
|
||||
config.addAllowedMethod("POST")
|
||||
config.addAllowedHeader("Authorization")
|
||||
|
||||
val source = UrlBasedCorsConfigurationSource()
|
||||
|
||||
source.registerCorsConfiguration("/**", config)
|
||||
|
||||
return CorsWebFilter(source)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class SpringController {
|
||||
}
|
||||
|
||||
//Embed pages
|
||||
@RequestMapping("/embed/calendar{id}")
|
||||
@RequestMapping("/embed/calendar/{id}")
|
||||
@Deprecated("This remains solely for backwards compat for users", ReplaceWith("N/a"))
|
||||
fun oldEmbedCalendar(model: MutableMap<String, Any>, swe: ServerWebExchange, @PathVariable id: String):
|
||||
Mono<String> {
|
||||
@@ -126,7 +126,7 @@ class SpringController {
|
||||
return Mono.just("redirect:/embed/$id/calendar/1")
|
||||
}
|
||||
|
||||
@RequestMapping("/embed/{id}calendar/{num}")
|
||||
@RequestMapping("/embed/{id}/calendar/{num}")
|
||||
fun embedCalendarWithNum(model: MutableMap<String, Any>, swe: ServerWebExchange, @PathVariable id: String,
|
||||
@PathVariable num: String): Mono<String> {
|
||||
return DiscordAccountHandler.getEmbedAccount(swe)
|
||||
|
||||
Reference in New Issue
Block a user