init
This commit is contained in:
commit
217642cd6b
18 changed files with 877 additions and 0 deletions
65
.gitignore
vendored
Normal file
65
.gitignore
vendored
Normal file
|
|
@ -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/
|
||||||
29
Dockerfile
Normal file
29
Dockerfile
Normal file
|
|
@ -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"]
|
||||||
7
README.md
Normal file
7
README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Homepage
|
||||||
|
|
||||||
|
## Package
|
||||||
|
```
|
||||||
|
./gradlew build
|
||||||
|
```
|
||||||
|
|
||||||
92
build.gradle.kts
Normal file
92
build.gradle.kts
Normal file
|
|
@ -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<KotlinJvmCompile>().configureEach {
|
||||||
|
compilerOptions {
|
||||||
|
allWarningsAsErrors = false
|
||||||
|
jvmTarget.set(JVM_21)
|
||||||
|
freeCompilerArgs.add("-Xjvm-default=all")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
withType<Test> {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
named<ShadowJar>("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")
|
||||||
|
}
|
||||||
|
|
||||||
2
gradle.properties
Normal file
2
gradle.properties
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
org.gradle.caching=true
|
||||||
|
org.gradle.configuration-cache=true
|
||||||
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -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
|
||||||
249
gradlew
vendored
Executable file
249
gradlew
vendored
Executable file
|
|
@ -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" "$@"
|
||||||
92
gradlew.bat
vendored
Normal file
92
gradlew.bat
vendored
Normal file
|
|
@ -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
|
||||||
9
homepage.iml
Normal file
9
homepage.iml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
1
settings.gradle.kts
Normal file
1
settings.gradle.kts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
rootProject.name = "Homepage"
|
||||||
88
src/main/kotlin/at/dokkae/homepage/Homepage.kt
Normal file
88
src/main/kotlin/at/dokkae/homepage/Homepage.kt
Normal file
|
|
@ -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<Message>()
|
||||||
|
val subscribers = CopyOnWriteArrayList<Sse>()
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
8
src/main/kotlin/at/dokkae/homepage/templates/Index.kt
Normal file
8
src/main/kotlin/at/dokkae/homepage/templates/Index.kt
Normal file
|
|
@ -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<Message> = listOf()) : ViewModel {
|
||||||
|
override fun template(): String = "Index"
|
||||||
|
}
|
||||||
0
src/main/kte/.jteroot
Normal file
0
src/main/kte/.jteroot
Normal file
160
src/main/kte/Index.kte
Normal file
160
src/main/kte/Index.kte
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
@import at.dokkae.homepage.templates.Index
|
||||||
|
|
||||||
|
@param model: Index
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
<title>Simple Chat — http4k + JTE + htmx</title>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.8/dist/htmx.min.js" integrity="sha384-/TgkGk7p307TH7EXJDuUlgG3Ce1UVolAOFopFekQkkXihi5u/6OCvVKyz1W+idaz" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/htmx-ext-sse@2.2.4" integrity="sha384-A986SAtodyH8eg8x8irJnYUk7i9inVQqYigD6qZ9evobksGNIXfeFvDwLSHcp31N" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #f5f5f7;
|
||||||
|
--card: #ffffff;
|
||||||
|
--border: #d0d0d5;
|
||||||
|
--bubble-self: #daf0ff;
|
||||||
|
--bubble-other: #ececec;
|
||||||
|
--text-dark: #222;
|
||||||
|
--text-light: #666;
|
||||||
|
--radius: 12px;
|
||||||
|
--spacing: 12px;
|
||||||
|
--font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: var(--font);
|
||||||
|
background: var(--bg);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 32px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chat {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 560px;
|
||||||
|
background: var(--card);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
padding: 20px;
|
||||||
|
box-shadow: 0 4px 20px rgba(0,0,0,0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
font-size: 1.4rem;
|
||||||
|
color: var(--text-dark);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messages {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
gap: var(--spacing);
|
||||||
|
margin-bottom: 20px;
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Nice scrollbar */
|
||||||
|
#messages::-webkit-scrollbar { width: 6px; }
|
||||||
|
#messages::-webkit-scrollbar-thumb {
|
||||||
|
background: #bbb;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
padding: 10px 14px;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
max-width: 85%;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
line-height: 1.35;
|
||||||
|
color: var(--text-dark);
|
||||||
|
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-author {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: var(--text-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-self {
|
||||||
|
align-self: flex-end;
|
||||||
|
background: var(--bubble-self);
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-other {
|
||||||
|
align-self: flex-start;
|
||||||
|
background: var(--bubble-other);
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"] {
|
||||||
|
flex: 1;
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 1rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 10px 16px;
|
||||||
|
background: #1e88ff;
|
||||||
|
border: none;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
color: white;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background: #0c74e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.note {
|
||||||
|
font-size: 0.82rem;
|
||||||
|
color: var(--text-light);
|
||||||
|
margin-top: 14px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body hx-ext="sse">
|
||||||
|
<main id="chat">
|
||||||
|
<h1>Simple Chat</h1>
|
||||||
|
|
||||||
|
<div id="messages" sse-connect="/message-events" sse-swap="message" hx-swap="afterbegin">
|
||||||
|
@for (message in model.messages.reversed())
|
||||||
|
@template.partials.Message(message)
|
||||||
|
@endfor
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<form hx-post="/messages" hx-swap="none">
|
||||||
|
<input id="username-input" type="text" name="author" placeholder="name (optional)">
|
||||||
|
<input id="message-input" type="text" name="message" placeholder="your message" required>
|
||||||
|
<button type="submit"
|
||||||
|
hx-on::after-request="if(event.detail.successful)document.getElementById('message-input').value = ''">
|
||||||
|
Send
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p style="font-size: .9rem; color: #666">No auth — anyone can post. Messages are stored only in memory.</p>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
11
src/main/kte/partials/Message.kte
Normal file
11
src/main/kte/partials/Message.kte
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
@import at.dokkae.homepage.Message
|
||||||
|
|
||||||
|
@param message: Message
|
||||||
|
|
||||||
|
<div class="message">
|
||||||
|
<strong>${message.author}</strong>:
|
||||||
|
${message.content}
|
||||||
|
<span style="color:#888; font-size:.8rem;">
|
||||||
|
(${message.createdAt.toString()})
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
19
src/test/kotlin/at/dokkae/homepage/HomepageClient.kt
Normal file
19
src/test/kotlin/at/dokkae/homepage/HomepageClient.kt
Normal file
|
|
@ -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())
|
||||||
|
}
|
||||||
18
src/test/kotlin/at/dokkae/homepage/HomepageTest.kt
Normal file
18
src/test/kotlin/at/dokkae/homepage/HomepageTest.kt
Normal file
|
|
@ -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"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue