-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#3): http restructure, routing & parsing work
- Loading branch information
1 parent
f8db32c
commit 02da077
Showing
6 changed files
with
71 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
kraftx/http/src/main/kotlin/sh/illumi/kraft/x/http/HttpServer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package sh.illumi.kraft.x.http | ||
|
||
import io.netty.bootstrap.ServerBootstrap | ||
import io.netty.channel.ChannelInitializer | ||
import io.netty.channel.nio.NioEventLoopGroup | ||
import io.netty.channel.socket.SocketChannel | ||
import io.netty.handler.codec.http.HttpRequestDecoder | ||
import io.netty.handler.codec.http.HttpResponseEncoder | ||
import io.netty.handler.logging.LogLevel | ||
import io.netty.handler.logging.LoggingHandler | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import sh.illumi.kraft.layer.RootLayer | ||
import sh.illumi.kraft.x.http.routing.Route | ||
|
||
/** | ||
* A service that provides an HTTP server. It must be run on the [RootLayer] of | ||
* the application. | ||
*/ | ||
class HttpServer( | ||
private val layer: RootLayer<*>, | ||
) { | ||
private lateinit var serverJob: Job | ||
val rootRoute = Route() | ||
|
||
private val eventLoopGroup = NioEventLoopGroup() | ||
private val workerGroup = NioEventLoopGroup() | ||
private val nettyServerBootstrap = ServerBootstrap() | ||
.group(eventLoopGroup, workerGroup) | ||
.handler(LoggingHandler(LogLevel.INFO)) | ||
.childHandler(object : ChannelInitializer<SocketChannel>() { | ||
override fun initChannel(ch: SocketChannel) { | ||
val p = ch.pipeline(); | ||
p.addLast(HttpRequestDecoder()); | ||
p.addLast(HttpResponseEncoder()); | ||
// p.addLast(new CustomHttpServerHandler()); | ||
} | ||
}); | ||
|
||
fun startServer() { | ||
serverJob = layer.coroutineScope.launch { | ||
|
||
} | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
kraftx/http/src/main/kotlin/sh/illumi/kraft/x/http/HttpService.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters