Skip to content

Commit

Permalink
KTOR-7962 Fix fullstack-mpp sample (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
stokado authored Dec 18, 2024
1 parent 2d0b0e5 commit 302bca8
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 102 deletions.
86 changes: 0 additions & 86 deletions fullstack-mpp/build.gradle

This file was deleted.

83 changes: 83 additions & 0 deletions fullstack-mpp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<Jar>("backendJar") {
val frontendBrowserProductionWebpack = tasks.getByName<KotlinWebpack>("frontendBrowserProductionWebpack")
dependsOn(frontendBrowserProductionWebpack)
from(frontendBrowserProductionWebpack.outputDirectory, frontendBrowserProductionWebpack.mainOutputFileName)
}

tasks.register<JavaExec>("run") {
dependsOn(backendJar)
mainClass.set("io.ktor.samples.fullstack.backend.BackendCodeKt")
classpath = files(configurations.getByName("backendRuntimeClasspath"), backendJar)
args = listOf<String>()
}
10 changes: 0 additions & 10 deletions fullstack-mpp/settings.gradle

This file was deleted.

18 changes: 18 additions & 0 deletions fullstack-mpp/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 1 addition & 3 deletions fullstack-mpp/src/backendMain/kotlin/BackendCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ fun Application.main() {
get("/test") {
call.respond("I am a test response")
}
static("/static") {
resources()
}
staticResources(remotePath = "/static", basePackage = null)
}
}

Expand Down
4 changes: 1 addition & 3 deletions fullstack-mpp/src/frontendMain/kotlin/FrontendCode.kt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 302bca8

Please sign in to comment.