Grdykopląs Namorzyn
09/20/2024, 6:46 AMFernando
09/20/2024, 8:34 AMimplementation("io.ktor:ktor-server-cors:$ktor_version")
Install the plugin and allow any host to access it
embeddedServer(Netty, port = 8080) {
install(CORS) {
anyHost()
}
}
Grdykopląs Namorzyn
09/20/2024, 1:37 PMGrdykopląs Namorzyn
09/20/2024, 1:37 PMGrdykopląs Namorzyn
09/20/2024, 1:37 PMGrdykopląs Namorzyn
09/20/2024, 1:37 PMinstall(CORS) {
// albo:
anyHost() // Allow requests from any origin - you can restrict it later
// albo (jeśli allowCredentials = true), to musimy podać hosta:
allowHost("${WebUICfg.HOST}:${WebUICfg.PORT}", schemes = listOf("http", "https"))
allowMethod(HttpMethod.Get) // Allow specific methods or use HttpMethod.Any for all
allowMethod(<http://HttpMethod.Post|HttpMethod.Post>)
allowMethod(HttpMethod.Put)
allowMethod(HttpMethod.Options) // Allow OPTIONS requests (for preflight)
allowMethod(HttpMethod.Delete)
allowMethod(HttpMethod.Patch)
allowHeader(HttpHeaders.Authorization) // Allow any headers you need
allowHeader(HttpHeaders.ContentType) // Allow the Content-Type header
allowHeader("MyCustomHeader")
allowCredentials = true // This is important to allow cookies to be sent
allowSameOrigin = true // Allow the SameSite lax policy by setting the proper CORS headers
}
Grdykopląs Namorzyn
09/20/2024, 1:40 PMAleksha
09/21/2024, 8:27 AMrun
task.
Kind of (assuming that the client module is named app
):
1)
tasks {
val resourcesMain by lazy { project.layout.buildDirectory.dir("resources/main").get().asFile }
register("runWithComposeApp") { dependsOn("appjsBrowserDevelopmentExecutableDistribution")
doLast {
copy {
from(File(rootDir, "app/build/dist/js/developmentExecutable"))
into(resourcesMain)
}
}
finalizedBy("run")
}
}
2) add to your Ktor backend this singlePageApplication route
routing {
singlePageApplication {
defaultPage = "index.html"
useResources = true
filesPath = ""
}
}Grdykopląs Namorzyn
09/21/2024, 7:54 PMGrdykopląs Namorzyn
09/21/2024, 7:57 PM> Configure project :composeApp
w: 'java' Gradle plugin is not compatible with 'org.jetbrains.kotlin.multiplatform' plugin.
Consider adding a new subproject with 'java' plugin where the KMP project is added as a dependency.
w: 'application' (also applies 'java' plugin) Gradle plugin is not compatible with 'org.jetbrains.kotlin.multiplatform' plugin.
Consider adding a new subproject with 'application' plugin where the KMP project is added as a dependency.
Grdykopląs Namorzyn
09/21/2024, 7:57 PM