diff --git a/fullstack-mpp/build.gradle b/fullstack-mpp/build.gradle deleted file mode 100644 index d48ab2fc..00000000 --- a/fullstack-mpp/build.gradle +++ /dev/null @@ -1,86 +0,0 @@ -buildscript { - repositories { - mavenLocal() - google() - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20" - } -} - -apply plugin: 'kotlin-multiplatform' - -kotlin { - targets { - js('frontend', IR) { - browser { - testTask { - // TODO: disable browser tests since we can't run it on teamcity agents yet - enabled = false - } - binaries.executable() - } - } - jvm('backend') { - } - } - - sourceSets.each { - it.dependencies { - implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.2")) - } - } - - sourceSets { - commonTest { - dependencies { - implementation "org.jetbrains.kotlin:kotlin-test-annotations-common" - implementation "org.jetbrains.kotlin:kotlin-test-common" - } - } - backendMain { - dependencies { - implementation "io.ktor:ktor-server-netty" - implementation "io.ktor:ktor-server-html-builder" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "ch.qos.logback:logback-classic:1.5.12" - } - } - backendTest { - dependencies { - implementation "org.jetbrains.kotlin:kotlin-test" - implementation "org.jetbrains.kotlin:kotlin-test-junit" - } - } - frontendMain { - dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-js" - implementation "org.jetbrains.kotlin:kotlin-test-js" - implementation "io.ktor:ktor-client-core" - implementation "io.ktor:ktor-client-js" - } - } - } -} - -repositories { - mavenCentral() -} - -tasks.getByName('frontendBrowserProductionWebpack') { - outputFileName = 'output.js' -} - -tasks.getByName('backendJar') { - dependsOn(tasks.getByName('frontendBrowserProductionWebpack')) - def frontendBrowserProductionWebpack = tasks.getByName('frontendBrowserProductionWebpack') - from(new File(frontendBrowserProductionWebpack.destinationDirectory, frontendBrowserProductionWebpack.outputFileName)) -} - -task run(type: JavaExec, dependsOn: [backendJar]) { - main = "io.ktor.samples.fullstack.backend.BackendCodeKt" - classpath(configurations.backendRuntimeClasspath, backendJar) - args = [] -} diff --git a/fullstack-mpp/build.gradle.kts b/fullstack-mpp/build.gradle.kts new file mode 100644 index 00000000..06b5bfbd --- /dev/null +++ b/fullstack-mpp/build.gradle.kts @@ -0,0 +1,83 @@ +import org.jetbrains.kotlin.gradle.targets.js.webpack.* + +plugins { + id("org.jetbrains.kotlin.multiplatform") version "2.1.0" +} + +kotlin { + targets { + js("frontend", IR) { + browser { + testTask { + // TODO: disable browser tests since we can"t run it on teamcity agents yet + enabled = false + } + webpackTask { + mainOutputFileName = "output.js" + } + binaries.executable() + } + } + jvm("backend") { + } + } + + sourceSets.forEach { + it.dependencies { + implementation(project.dependencies.enforcedPlatform("io.ktor:ktor-bom:3.0.2")) + } + } + + sourceSets { + commonTest { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-test-annotations-common") + implementation("org.jetbrains.kotlin:kotlin-test-common") + } + } + } + + sourceSets { + val backendMain by getting { + dependencies { + implementation("io.ktor:ktor-server-netty") + implementation("io.ktor:ktor-server-html-builder") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("ch.qos.logback:logback-classic:1.5.12") + } + } + val backendTest by getting { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-test") + implementation("org.jetbrains.kotlin:kotlin-test-junit") + } + } + val frontendMain by getting { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-js") + implementation("org.jetbrains.kotlin:kotlin-test-js") + implementation("io.ktor:ktor-client-core") + implementation("io.ktor:ktor-client-js") + // specify ws version explicitly to fix webpack task + implementation(npm("ws", "8.18.0")) // TODO should be removed, after ktor 3.0.3 release (KTOR-7912) + } + } + } +} + +repositories { + mavenCentral() +} + +val backendJar = tasks.named("backendJar") { + val frontendBrowserProductionWebpack = tasks.getByName("frontendBrowserProductionWebpack") + dependsOn(frontendBrowserProductionWebpack) + from(frontendBrowserProductionWebpack.outputDirectory, frontendBrowserProductionWebpack.mainOutputFileName) +} + +tasks.register("run") { + dependsOn(backendJar) + mainClass.set("io.ktor.samples.fullstack.backend.BackendCodeKt") + classpath = files(configurations.getByName("backendRuntimeClasspath"), backendJar) + args = listOf() +} diff --git a/fullstack-mpp/settings.gradle b/fullstack-mpp/settings.gradle deleted file mode 100644 index 2274b231..00000000 --- a/fullstack-mpp/settings.gradle +++ /dev/null @@ -1,10 +0,0 @@ -rootProject.name = 'ktor-samples' - -def module(group, name) { - include(name) - project(":$name").projectDir = file("$group/$name") -} - -// --------------------------- - -module('samples', 'fullstack-mpp') diff --git a/fullstack-mpp/settings.gradle.kts b/fullstack-mpp/settings.gradle.kts new file mode 100644 index 00000000..2ab20df3 --- /dev/null +++ b/fullstack-mpp/settings.gradle.kts @@ -0,0 +1,18 @@ +rootProject.name = "ktor-samples" + +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } +} + +fun module(group: String, name: String) { + include(name) + project(":$name").projectDir = file("$group/$name") +} + +// --------------------------- + +module("samples", "fullstack-mpp") diff --git a/fullstack-mpp/src/backendMain/kotlin/BackendCode.kt b/fullstack-mpp/src/backendMain/kotlin/BackendCode.kt index be45feb4..358f60ce 100644 --- a/fullstack-mpp/src/backendMain/kotlin/BackendCode.kt +++ b/fullstack-mpp/src/backendMain/kotlin/BackendCode.kt @@ -32,9 +32,7 @@ fun Application.main() { get("/test") { call.respond("I am a test response") } - static("/static") { - resources() - } + staticResources(remotePath = "/static", basePackage = null) } } diff --git a/fullstack-mpp/src/frontendMain/kotlin/FrontendCode.kt b/fullstack-mpp/src/frontendMain/kotlin/FrontendCode.kt index 0b4d1d95..55112f48 100644 --- a/fullstack-mpp/src/frontendMain/kotlin/FrontendCode.kt +++ b/fullstack-mpp/src/frontendMain/kotlin/FrontendCode.kt @@ -1,13 +1,11 @@ package io.ktor.samples.fullstack.frontend import io.ktor.client.* -import io.ktor.client.call.body import io.ktor.client.engine.js.* import io.ktor.client.request.* import io.ktor.http.* import io.ktor.samples.fullstack.common.* -import kotlinx.browser.document -import kotlinx.browser.window +import kotlinx.browser.* import kotlinx.coroutines.* private val client = HttpClient(Js)