Refactor app configuration
This commit is contained in:
@@ -1,27 +1,15 @@
|
|||||||
package eventDemo
|
package eventDemo
|
||||||
|
|
||||||
import eventDemo.plugins.configureCommandHandler
|
|
||||||
import eventDemo.plugins.configureHTTP
|
|
||||||
import eventDemo.plugins.configureKoin
|
|
||||||
import eventDemo.plugins.configureRouting
|
|
||||||
import eventDemo.plugins.configureSecurity
|
|
||||||
import eventDemo.plugins.configureSerialization
|
|
||||||
import eventDemo.plugins.configureSockets
|
|
||||||
import io.ktor.server.application.Application
|
import io.ktor.server.application.Application
|
||||||
import io.ktor.server.engine.embeddedServer
|
import io.ktor.server.engine.embeddedServer
|
||||||
import io.ktor.server.netty.Netty
|
import io.ktor.server.netty.Netty
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module, watchPaths = listOf("classes"))
|
embeddedServer(
|
||||||
.start(wait = true)
|
factory = Netty,
|
||||||
}
|
port = 8080,
|
||||||
|
host = "0.0.0.0",
|
||||||
fun Application.module() {
|
module = Application::configure,
|
||||||
configureSecurity()
|
watchPaths = listOf("classes"),
|
||||||
configureSerialization()
|
).start(wait = true)
|
||||||
configureSockets()
|
|
||||||
configureHTTP()
|
|
||||||
configureRouting()
|
|
||||||
configureKoin()
|
|
||||||
configureCommandHandler()
|
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/main/kotlin/eventDemo/Configure.kt
Normal file
19
src/main/kotlin/eventDemo/Configure.kt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package eventDemo
|
||||||
|
|
||||||
|
import eventDemo.plugins.configureHTTP
|
||||||
|
import eventDemo.plugins.configureKoin
|
||||||
|
import eventDemo.plugins.configureRouting
|
||||||
|
import eventDemo.plugins.configureSecurity
|
||||||
|
import eventDemo.plugins.configureSerialization
|
||||||
|
import eventDemo.plugins.configureSockets
|
||||||
|
import io.ktor.server.application.Application
|
||||||
|
|
||||||
|
fun Application.configure() {
|
||||||
|
configureSecurity()
|
||||||
|
configureSerialization()
|
||||||
|
configureSockets()
|
||||||
|
configureHTTP()
|
||||||
|
configureRouting()
|
||||||
|
configureKoin()
|
||||||
|
configureCommandHandler()
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package eventDemo.plugins
|
package eventDemo
|
||||||
|
|
||||||
import eventDemo.app.actions.playNewCard.PlayCardCommandHandler
|
import eventDemo.app.actions.playNewCard.PlayCardCommandHandler
|
||||||
import io.ktor.server.application.Application
|
import io.ktor.server.application.Application
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package eventDemo.app.actions
|
package eventDemo.app.actions
|
||||||
|
|
||||||
import eventDemo.module
|
import eventDemo.configure
|
||||||
import eventDemo.shared.GameId
|
import eventDemo.shared.GameId
|
||||||
import eventDemo.shared.entity.Card
|
import eventDemo.shared.entity.Card
|
||||||
import eventDemo.shared.event.CardIsPlayedEvent
|
import eventDemo.shared.event.CardIsPlayedEvent
|
||||||
@@ -27,7 +27,7 @@ class CardTest :
|
|||||||
testApplication {
|
testApplication {
|
||||||
application {
|
application {
|
||||||
stopKoin()
|
stopKoin()
|
||||||
module()
|
configure()
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = GameId()
|
val id = GameId()
|
||||||
@@ -52,7 +52,7 @@ class CardTest :
|
|||||||
val card: Card = Card.NumericCard(1, Card.Color.Blue)
|
val card: Card = Card.NumericCard(1, Card.Color.Blue)
|
||||||
application {
|
application {
|
||||||
stopKoin()
|
stopKoin()
|
||||||
module()
|
configure()
|
||||||
val eventStream by inject<GameEventStream>()
|
val eventStream by inject<GameEventStream>()
|
||||||
eventStream.publish(
|
eventStream.publish(
|
||||||
CardIsPlayedEvent(id, Card.NumericCard(2, Card.Color.Yellow)),
|
CardIsPlayedEvent(id, Card.NumericCard(2, Card.Color.Yellow)),
|
||||||
|
|||||||
Reference in New Issue
Block a user