commit 217642cd6b2c29c9df8afe67c3d294f15449ead3 Author: Dokkae6949 Date: Fri Dec 12 23:07:05 2025 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bbba7e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +################### +### Environment ### +################### + +.env +.env.* +!.env.example + +############## +### Gradle ### +############## + +.gradle +**/build/ +!**/src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +############## +### Kotlin ### +############## + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +# Kotlin Gradle plugin data, see https://kotlinlang.org/docs/whatsnew20.html#new-directory-for-kotlin-data-in-gradle-projects +.kotlin/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cb50b4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# --- Stage 1: Build the JAR --- +FROM gradle:9.2.1-jdk21 AS build + +# Set working dir +WORKDIR /app + +# Copy Gradle files first (for caching) +COPY --chown=gradle:gradle build.gradle.kts settings.gradle.kts gradle.properties gradlew ./ +COPY --chown=gradle:gradle gradle ./gradle + +# Copy source code +COPY --chown=gradle:gradle src ./src + +# Build the fat jar +RUN ./gradlew clean shadowJar --no-daemon + +# --- Stage 2: Run the app --- +FROM eclipse-temurin:21-jdk-alpine + +WORKDIR /app + +# Copy the built JAR from the build stage +COPY --from=build /app/build/libs/*.jar app.jar + +# Expose port (same as your server) +EXPOSE 9000 + +# Run the app +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..d1cd0b3 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Homepage + +## Package +``` +./gradlew build +``` + diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..75d553e --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,92 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.JavaVersion.VERSION_21 +import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21 +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile +import kotlin.io.path.Path + +plugins { + kotlin("jvm") version "2.2.20" + + id("gg.jte.gradle") version "3.2.1" + id("com.gradleup.shadow") version "9.3.0" +} + +buildscript { + repositories { + mavenCentral() + gradlePluginPortal() + } + + dependencies { + } +} + +kotlin { + jvmToolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } +} + +jte { + sourceDirectory.set(Path("src/main/kte")) + targetDirectory.set(Path("${layout.buildDirectory.get()}/classes/jte")) + + precompile() +} + +sourceSets.main { + resources.srcDir("${layout.buildDirectory.get()}/classes/jte") +} + +repositories { + mavenCentral() +} + +tasks { + withType().configureEach { + compilerOptions { + allWarningsAsErrors = false + jvmTarget.set(JVM_21) + freeCompilerArgs.add("-Xjvm-default=all") + } + } + + withType { + useJUnitPlatform() + } + + named("shadowJar") { + manifest { + attributes("Main-Class" to "at.dokkae.homepage.HomepageKt") + } + + dependsOn("precompileJte") + + from("${layout.buildDirectory.get()}/classes/jte") + + archiveFileName.set("app.jar") + + exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA") + } + + java { + sourceCompatibility = VERSION_21 + targetCompatibility = VERSION_21 + } +} + +dependencies { + implementation(platform("org.http4k:http4k-bom:6.23.1.0")) + implementation("org.http4k:http4k-client-okhttp") + implementation("org.http4k:http4k-core") + implementation("org.http4k:http4k-server-jetty") + implementation("org.http4k:http4k-template-jte") + implementation("org.http4k:http4k-web-htmx") + implementation("gg.jte:jte-kotlin:3.2.1") + testImplementation("org.http4k:http4k-testing-approval") + testImplementation("org.http4k:http4k-testing-hamkrest") + testImplementation("org.junit.jupiter:junit-jupiter-api:6.0.0") + testImplementation("org.junit.jupiter:junit-jupiter-engine:6.0.0") + testImplementation("org.junit.platform:junit-platform-launcher:6.0.0") +} + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..216f58e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.caching=true +org.gradle.configuration-cache=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2a84e18 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/homepage.iml b/homepage.iml new file mode 100644 index 0000000..8021953 --- /dev/null +++ b/homepage.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..b643262 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "Homepage" \ No newline at end of file diff --git a/src/main/kotlin/at/dokkae/homepage/Homepage.kt b/src/main/kotlin/at/dokkae/homepage/Homepage.kt new file mode 100644 index 0000000..55a89ca --- /dev/null +++ b/src/main/kotlin/at/dokkae/homepage/Homepage.kt @@ -0,0 +1,88 @@ +package at.dokkae.homepage + +import at.dokkae.homepage.extensions.Precompiled +import at.dokkae.homepage.templates.Index +import org.http4k.core.HttpHandler +import org.http4k.core.Method.* +import org.http4k.core.Response +import org.http4k.core.Status +import org.http4k.core.body.form +import org.http4k.core.getFirst +import org.http4k.core.toParametersMap +import org.http4k.routing.bindHttp +import org.http4k.routing.bindSse +import org.http4k.routing.poly +import org.http4k.routing.routes +import org.http4k.routing.sse +import org.http4k.server.Jetty +import org.http4k.server.asServer +import org.http4k.sse.Sse +import org.http4k.sse.SseMessage +import org.http4k.sse.SseResponse +import org.http4k.template.JTETemplates +import org.http4k.template.ViewModel +import org.jetbrains.kotlin.backend.common.push +import java.time.Instant +import java.util.UUID +import java.util.concurrent.CopyOnWriteArrayList +import kotlin.concurrent.thread + +data class Message ( + val author: String, + val content: String, + val createdAt: Instant = Instant.now(), + val id: UUID = UUID.randomUUID(), +) : ViewModel { + override fun template(): String = "partials/Message" +} + +fun main() { + val messages = CopyOnWriteArrayList() + val subscribers = CopyOnWriteArrayList() + val renderer = JTETemplates().Precompiled("build/classes/jte") + + messages.push(Message("Kurisu", "Hello World!")) + messages.push(Message("Violet", "Haii Kurisu!")) + + val indexHandler: HttpHandler = { + Response(Status.OK).body(renderer(Index(messages))) + } + + val sse = sse( + "/message-events" bindSse { req -> + SseResponse { sse -> + subscribers.add(sse) + + sse.onClose { subscribers.remove(sse) } + } + } + ) + + val http = routes( + "/" bindHttp GET to indexHandler, + + "/messages" bindHttp POST to { req -> + val params = req.form().toParametersMap() + val author = params.getFirst("author").takeIf { !it.isNullOrBlank() } ?: "Anonymous" + val message = params.getFirst("message") + + if (message == null) { + Response(Status.BAD_REQUEST) + } else { + val msg = Message(author, message) + val sseMsg = SseMessage.Data(renderer(msg)) + + messages.push(msg) + subscribers.forEach { + thread { it.send(sseMsg) } + } + + Response(Status.OK) + } + } + ) + + poly(http, sse).asServer(Jetty(port = 9000)).start() + + println("Server started on http://localhost:9000") +} diff --git a/src/main/kotlin/at/dokkae/homepage/extensions/JteTemplates.kt b/src/main/kotlin/at/dokkae/homepage/extensions/JteTemplates.kt new file mode 100644 index 0000000..49e1963 --- /dev/null +++ b/src/main/kotlin/at/dokkae/homepage/extensions/JteTemplates.kt @@ -0,0 +1,20 @@ +package at.dokkae.homepage.extensions + +import gg.jte.ContentType +import gg.jte.TemplateEngine +import gg.jte.output.StringOutput +import org.http4k.template.JTETemplates +import org.http4k.template.ViewModel +import org.http4k.template.ViewNotFound +import java.io.File + +fun JTETemplates.Precompiled(classTemplateDir: String) = + fun(viewModel: ViewModel): String { + val templateName = viewModel.template() + ".kte" + + val templateEngine = TemplateEngine.createPrecompiled(File(classTemplateDir).toPath(), ContentType.Html) + + return if (templateEngine.hasTemplate(templateName)) + StringOutput().also { templateEngine.render(templateName, viewModel, it); }.toString() + else throw ViewNotFound(viewModel) + } \ No newline at end of file diff --git a/src/main/kotlin/at/dokkae/homepage/templates/Index.kt b/src/main/kotlin/at/dokkae/homepage/templates/Index.kt new file mode 100644 index 0000000..1258984 --- /dev/null +++ b/src/main/kotlin/at/dokkae/homepage/templates/Index.kt @@ -0,0 +1,8 @@ +package at.dokkae.homepage.templates + +import at.dokkae.homepage.Message +import org.http4k.template.ViewModel + +data class Index(val messages: List = listOf()) : ViewModel { + override fun template(): String = "Index" +} \ No newline at end of file diff --git a/src/main/kte/.jteroot b/src/main/kte/.jteroot new file mode 100644 index 0000000..e69de29 diff --git a/src/main/kte/Index.kte b/src/main/kte/Index.kte new file mode 100644 index 0000000..0ceb8b2 --- /dev/null +++ b/src/main/kte/Index.kte @@ -0,0 +1,160 @@ +@import at.dokkae.homepage.templates.Index + +@param model: Index + + + + + + + Simple Chat — http4k + JTE + htmx + + + + + + + +
+

Simple Chat

+ +
+ @for (message in model.messages.reversed()) + @template.partials.Message(message) + @endfor +
+ + +
+ + + +
+ +

No auth — anyone can post. Messages are stored only in memory.

+
+ + \ No newline at end of file diff --git a/src/main/kte/partials/Message.kte b/src/main/kte/partials/Message.kte new file mode 100644 index 0000000..91f406f --- /dev/null +++ b/src/main/kte/partials/Message.kte @@ -0,0 +1,11 @@ +@import at.dokkae.homepage.Message + +@param message: Message + +
+ ${message.author}: + ${message.content} + + (${message.createdAt.toString()}) + +
\ No newline at end of file diff --git a/src/test/kotlin/at/dokkae/homepage/HomepageClient.kt b/src/test/kotlin/at/dokkae/homepage/HomepageClient.kt new file mode 100644 index 0000000..b43a83d --- /dev/null +++ b/src/test/kotlin/at/dokkae/homepage/HomepageClient.kt @@ -0,0 +1,19 @@ +package at.dokkae.homepage + +import org.http4k.client.OkHttp +import org.http4k.core.HttpHandler +import org.http4k.core.Method.GET +import org.http4k.core.Request +import org.http4k.core.Response +import org.http4k.core.then +import org.http4k.filter.DebuggingFilters.PrintResponse + +fun main() { + val client: HttpHandler = OkHttp() + + val printingClient: HttpHandler = PrintResponse().then(client) + + val response: Response = printingClient(Request(GET, "http://localhost:9000/ping")) + + println(response.bodyString()) +} diff --git a/src/test/kotlin/at/dokkae/homepage/HomepageTest.kt b/src/test/kotlin/at/dokkae/homepage/HomepageTest.kt new file mode 100644 index 0000000..782ed31 --- /dev/null +++ b/src/test/kotlin/at/dokkae/homepage/HomepageTest.kt @@ -0,0 +1,18 @@ +package at.dokkae.homepage + +import org.http4k.core.Method.GET +import org.http4k.core.Request +import org.http4k.core.Response +import org.http4k.core.Status.Companion.OK +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class HomepageTest { + @Test + fun `Ping test`() { + assertEquals( + Response(OK).body("pong"), + app(Request(GET, "/ping")) + ) + } +}