Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing changes #24

Merged
merged 6 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
thing runs again, and shuts down properly
  • Loading branch information
markiantorno committed Oct 27, 2020
commit 3e476de0a96c8c4a5c68aad8ad74628c353b981e
28 changes: 12 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,19 @@ tasks.getByName<JavaExec>("run") {
dependsOn(tasks.getByName<Jar>("jvmJar"))
classpath(tasks.getByName<Jar>("jvmJar"))
}
//
//tasks.withType<Jar> {
// manifest {
// attributes["Main-Class"] = "ServerKt"
// }
//
// // To add all of the dependencies otherwise a "NoClassDefFoundError" error
// from(sourceSets.main.get().output)
//
// dependsOn(configurations.runtimeClasspath)
// from({
// configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
// })
//}

tasks.withType<JavaCompile>().configureEach {
options.compilerArgs = listOf("-Xmx2g", "-XX:MaxMetaspaceSize=512m")
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "ServerKt"
}

// To add all of the dependencies otherwise a "NoClassDefFoundError" error
from(sourceSets.main.get().output)

dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/jvmMain/kotlin/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import routes.validationRoutes
import routes.versionRoutes

/**
* Entry point of the application. This function is referenced in the resources/application.conf file (see the line
* that says `modules = [ ModuleKt.module ]`, pointing to this method.
* Entry point of the application.
*/
fun Application.module() {
// Any DB initialization will go here.
Expand Down Expand Up @@ -48,13 +47,13 @@ fun Application.module() {
// Separating this function with its dependencies allows us to provide several modules with
// the same code and different data-sources living in the same application,
// and to provide mocked instances for doing integration tests.
start()
setup()
}

/**
* Application extension function where we configure Ktor application with features, interceptors and routing.
*/
fun Application.start() {
fun Application.setup() {

install(CallLogging) {
level = Level.DEBUG
Expand Down
11 changes: 5 additions & 6 deletions src/jvmMain/kotlin/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ fun startServer(args: Array<String>) {
val environment = System.getenv()["ENVIRONMENT"] ?: handleDefaultEnvironment()
val config = extractConfig(environment, HoconApplicationConfig(ConfigFactory.load()))

embeddedServer(Jetty,host = config.host, port = config.port) {
engine = embeddedServer(Jetty, host = config.host, port = config.port) {
println("Starting instance in ${config.host}:${config.port}")
module()
}.start(wait = true)
}

engine.start(wait = true)
}

/**
Expand All @@ -78,10 +80,7 @@ private fun runningAsDesktopApp(args: Array<String>): Boolean {
return args.isNotEmpty() && Params.hasParam(args, LOCAL_APP_FLAG) && !Params.hasParam(args, FULL_STACK_FLAG)
}

data class Config(
val host: String,
val port: Int,
)
data class Config(val host: String, val port: Int)

@KtorExperimentalAPI
fun extractConfig(environment: String, hoconConfig: HoconApplicationConfig): Config {
Expand Down
2 changes: 1 addition & 1 deletion src/jvmMain/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ ktor {
}
}
application {
modules = [ ModuleKt.module ]
modules = [ ServerKt.module ]
}
}