Skip to content
Permalink
Browse files

Initial commit

Signed-off-by: Till Kottmann <me@deletescape.ch>
  • Loading branch information
deletescape committed Sep 28, 2019
0 parents commit d82e4635e0c19cc5dd4cb681661941742c9c367e
@@ -0,0 +1,16 @@
**/.gradle
**/build
**/out
*.iml
*.ipr
*.iws
!/.idea/copyright
!/.idea/codeStyles
/.idea/dictionaries
/.idea/inspectionProfiles
/.idea/libraries
/.idea/caches
/.idea/markdown-navigator
/.idea/*.xml
!/.idea/saveactions_settings.xml
/.idea/.name
@@ -0,0 +1,10 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SaveActionSettings">
<option name="actions">
<set>
<option value="activate" />
<option value="reformatChangedCode" />
</set>
</option>
<option name="configurationPath" value="" />
</component>
</project>
21 LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Till Kottmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,32 @@
val ktor_version: String by rootProject
val kotlin_version: String by rootProject
val logback_version: String by rootProject

plugins {
application
kotlin("jvm")
}

application {
mainClassName = "io.ktor.server.netty.EngineMain"
}

dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
compile("io.ktor:ktor-server-netty:$ktor_version")
compile("ch.qos.logback:logback-classic:$logback_version")
compile("io.ktor:ktor-metrics:$ktor_version")
compile("io.ktor:ktor-server-core:$ktor_version")
compile("io.ktor:ktor-gson:$ktor_version")
compile(project(":pebble"))

compile("com.github.zensum:ktor-health-check:011a5a8")

testCompile("io.ktor:ktor-server-tests:$ktor_version")
}

kotlin.sourceSets["main"].kotlin.srcDirs("src")
kotlin.sourceSets["test"].kotlin.srcDirs("test")

sourceSets["main"].resources.srcDirs("resources")
sourceSets["test"].resources.srcDirs("testresources")
@@ -0,0 +1,9 @@
ktor {
deployment {
port = 8080
port = ${?PORT}
}
application {
modules = [ dog.del.ApplicationKt.module ]
}
}
@@ -0,0 +1,12 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="trace">
<appender-ref ref="STDOUT"/>
</root>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
</configuration>
@@ -0,0 +1,3 @@
<html>
<p>Hello {{ name }}</p>
</html>
@@ -0,0 +1,58 @@
package dog.del

import com.mitchellbosecke.pebble.loader.ClasspathLoader
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.features.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.gson.*
import io.ktor.pebble.Pebble
import io.ktor.pebble.respondTemplate
import ktor_health_check.Health

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
install(Compression) {
gzip {
priority = 1.0
}
deflate {
priority = 10.0
minimumSize(1024) // condition
}
}

install(ContentNegotiation) {
gson {
}
}

install(Health) {
healthCheck("running") { true }
}

install(Pebble) {
loader(ClasspathLoader().apply {
prefix = "templates"
suffix = ".html"
})
}

routing {
get("/") {
call.respondTemplate("index", mapOf(
"name" to "world!"
))
}

get("/json/gson") {
call.respond(mapOf("hello" to "world"))
}
}
}

@@ -0,0 +1,20 @@
package dog.del

import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.withTestApplication
import kotlin.test.Test
import kotlin.test.assertEquals

class ApplicationTest {
@Test
fun `Application is running`() {
withTestApplication({ module(testing = true) }) {
handleRequest(HttpMethod.Get, "/healthz").apply {
assertEquals(HttpStatusCode.OK, response.status())
assertEquals("{\"running\":true}", response.content)
}
}
}
}
@@ -0,0 +1,37 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent

val version: String by project
val ktorVersion: String by project
val kotlinVersion: String by project
val logbackVersion: String by project

plugins {
base
kotlin("jvm") version "1.3.0"
}

allprojects {
group = "dog.del"
version = "2.0.0-SNAPSHOT"

apply(plugin = "kotlin")

repositories {
mavenLocal()
jcenter()
maven { url = uri("https://kotlin.bintray.com/ktor") }
maven { url = uri("https://plugins.gradle.org/m2/") }
maven { url = uri("https://jitpack.io") }
}

tasks.withType<Test> {
useJUnitPlatform {
includeEngines("junit-jupiter")
}

failFast = true
testLogging {
events = setOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED)
}
}
}
@@ -0,0 +1,4 @@
ktor_version=1.2.4
kotlin.code.style=official
kotlin_version=1.3.50
logback_version=1.2.1
Binary file not shown.
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit d82e463

Please sign in to comment.
You can’t perform that action at this time.