Skip to content

Commit

Permalink
Fix CORS for lyrics
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Dec 22, 2023
1 parent f52cbe3 commit 72d9b23
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
do
2 changes: 1 addition & 1 deletion music/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subprojects {
version = "3.5.0-SNAPSHOT"
version = "3.5.1-SNAPSHOT"
}
1 change: 0 additions & 1 deletion music/lyrics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fun DependencyHandlerScope.ktorDependency(dependency: Provider<*>) = implementat
exclude(module = "ktor-server-core")
}


tasks {
val generateDefaultResourceBundle by registering(GenerateDefaultTranslationBundleTask::class) {
defaultLocale = Locale("en", "GB")
Expand Down
23 changes: 15 additions & 8 deletions music/lyrics/src/main/kotlin/APIServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import io.ktor.util.*
import io.ktor.websocket.*
import kotlinx.coroutines.*
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import kotlinx.serialization.json.Json
import org.koin.core.component.inject
Expand Down Expand Up @@ -80,14 +83,18 @@ class APIServer : KtorExtensionPoint, KordExKoinComponent {
contentConverter = KotlinxWebsocketSerializationConverter(Json)
}
}
if (pluginOrNull(CORS) == null && BotConfig.ENVIRONMENT == Environment.DEVELOPMENT) {
install(CORS) {
allowMethod(HttpMethod.Options)
allowMethod(HttpMethod.Put)
allowMethod(HttpMethod.Delete)
allowMethod(HttpMethod.Patch)
allowHeader(HttpHeaders.Authorization)
install(CORS) {
allowMethod(HttpMethod.Options)
allowMethod(HttpMethod.Put)
allowMethod(HttpMethod.Delete)
allowMethod(HttpMethod.Patch)
allowHeader(HttpHeaders.Authorization)
if (BotConfig.ENVIRONMENT == Environment.DEVELOPMENT) {
anyHost()
} else {
allowSameOrigin = true
val url = Url(Config.LYRICS_WEB_URL)
allowHost(url.host, listOf(url.protocol.name))
}
}

Expand Down
2 changes: 1 addition & 1 deletion music/lyrics/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package dev.schlaubi.mikmusic.lyrics
import dev.schlaubi.mikbot.plugin.api.EnvironmentConfig

object Config : EnvironmentConfig() {
val LYRICS_WEB_URL by getEnv("http://localhost:3000")
val LYRICS_WEB_URL by getEnv("http://localhost:3001")
}

0 comments on commit 72d9b23

Please sign in to comment.