File tree Expand file tree Collapse file tree 5 files changed +31
-14
lines changed
kotlin/dev/datastar/kotlin/examples/httpserver Expand file tree Collapse file tree 5 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,7 @@ This example uses `Ktor` to serve the front end.
3232
3333## Java HTTP Server
3434
35- This example uses the plain Java ` HttpServer ` to serve the front end. ( [ code ] ( java-httpserver/server.kt ) )
35+ This example uses the plain Java ` HttpServer ` to serve the front end.
3636
37- ``` shell
38- cd ./java-httpserver ; jbang server.kt ; cd ..
39- ```
37+ - [ Java HTTP Server] ( java-httpserver/src/main/kotlin/dev/datastar/kotlin/examples/httpserver/Application.kt ) : Demonstrates integration with Java HTTP Server.
4038
Original file line number Diff line number Diff line change 1+ plugins {
2+ id(" org.jetbrains.kotlin.jvm" ) version " 2.2.0"
3+ application
4+ }
5+
6+ repositories {
7+ mavenCentral()
8+ }
9+
10+ application {
11+ mainClass = " dev.datastar.kotlin.examples.httpserver.ApplicationKt"
12+ }
13+
14+ dependencies {
15+ implementation(" dev.data-star.kotlin:kotlin-sdk:1.0.0-RC1" )
16+ implementation(" org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2" )
17+ }
18+
19+ java {
20+ toolchain {
21+ languageVersion = JavaLanguageVersion .of(21 )
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package dev.datastar.kotlin.examples.httpserver
2+
13import com.sun.net.httpserver.HttpExchange
24import com.sun.net.httpserver.HttpServer
35import dev.datastar.kotlin.sdk.Response
46import dev.datastar.kotlin.sdk.ServerSentEventGenerator
57import kotlinx.coroutines.flow.MutableStateFlow
68import kotlinx.coroutines.runBlocking
7- import java.io.File
89import java.net.InetSocketAddress
910import java.util.concurrent.Executors
1011
11- // /usr/bin/env jbang "$0" "$@" ; exit $?
12- // JAVA 21
13- // KOTLIN 2.2.0
14- // DEPS dev.data-star.kotlin:kotlin-sdk:1.0.0-RC1
15- // DEPS org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2
16-
1712
1813fun main (): Unit = server().run {
1914 start()
@@ -29,9 +24,9 @@ fun server(
2924
3025 executor = Executors .newVirtualThreadPerTaskExecutor()
3126
32- val counterPage = File (
33- " ../front/ counter.html"
34- ).readBytes()
27+ val counterPage = object {}.javaClass.classLoader.getResource (
28+ " counter.html"
29+ )!! .readBytes()
3530
3631 createContext(" /" ) { exchange ->
3732 exchange.responseHeaders.add(" Content-Type" , " text/html" )
File renamed without changes.
Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ includeBuild("examples/spring/spring-webflux-example")
1111includeBuild(" examples/quarkus/quarkus-rest-example" )
1212includeBuild(" examples/quarkus/quarkus-qute-example" )
1313includeBuild(" examples/ktor/ktor-example" )
14+ includeBuild(" examples/java-httpserver" )
You can’t perform that action at this time.
0 commit comments