Skip to content

Commit

Permalink
feat(http): use ktor instead
Browse files Browse the repository at this point in the history
  • Loading branch information
LizAinslie committed Nov 6, 2024
1 parent 960e133 commit 7116110
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 193 deletions.
9 changes: 9 additions & 0 deletions core/src/main/kotlin/sh/illumi/kraft/layer/RootLayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ abstract class RootLayer(
@Suppress("LeakingThis")
override val services = ServiceContainer(this)

init {
@Suppress("LeakingThis")
instance = this
}

abstract suspend fun start()

companion object {
lateinit var instance: RootLayer
}
}
7 changes: 2 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[versions]
kotlinx-coroutines = "1.9.0"
slf4j = "2.0.16"
urilib = "1.0.12"
netty = "4.1.114.Final"
ktor = "3.0.0"
exposed = "0.56.0"
hikari = "6.0.0"

Expand All @@ -13,9 +12,7 @@ kotlinx-coroutines-slf4j = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-

slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }

netty-all = { module = "io.netty:netty-all", version.ref = "netty" }

urilib = { module = "com.oxyggen.net:urilib", version.ref = "urilib" }
ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" }

exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
Expand Down
3 changes: 1 addition & 2 deletions kraftx/http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ dependencies {

implementation(libs.slf4j.api)

implementation(libs.netty.all)
implementation(libs.urilib)
implementation(libs.ktor.server.core)

testImplementation(kotlin("test"))
testImplementation(libs.kotlinx.coroutines.test)
Expand Down
16 changes: 0 additions & 16 deletions kraftx/http/src/main/kotlin/sh/illumi/kraft/x/http/HttpMethod.kt

This file was deleted.

50 changes: 0 additions & 50 deletions kraftx/http/src/main/kotlin/sh/illumi/kraft/x/http/HttpServer.kt

This file was deleted.

22 changes: 0 additions & 22 deletions kraftx/http/src/main/kotlin/sh/illumi/kraft/x/http/call/Call.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package sh.illumi.kraft.x.http.extensions

import io.ktor.server.application.*
import io.ktor.server.engine.*
import sh.illumi.kraft.layer.RootLayer
import sh.illumi.kraft.layer.lazyProperty
import sh.illumi.kraft.service.Service

import sh.illumi.kraft.x.http.HttpServer
import sh.illumi.kraft.x.http.routing.Route
fun <TEngine, TConfiguration> RootLayer.embeddedServer(
factory: ApplicationEngineFactory<TEngine, TConfiguration>,
port: Int = 80,
host: String = "0.0.0.0",
watchPaths: List<String> = listOf(),
module: Application.() -> Unit
) where
TEngine : ApplicationEngine,
TConfiguration : ApplicationEngine.Configuration
= this.coroutineScope.embeddedServer(factory, port, host, watchPaths, this.coroutineScope.coroutineContext, module)

val RootLayer.httpServer: HttpServer by lazyProperty {
HttpServer(this)
}

fun Service.httpRouting(block: Route.() -> Unit) {
this.rootLayer.httpServer.rootRoute.apply(block)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package sh.illumi.kraft.x.http.extensions

import io.ktor.server.routing.*
import sh.illumi.kraft.layer.RootLayer
import sh.illumi.kraft.service.ServiceContainer

val RoutingContext.services: ServiceContainer get() = RootLayer.instance.services

This file was deleted.

0 comments on commit 7116110

Please sign in to comment.