diff --git a/pom.xml b/pom.xml index fe74bfb..1f88371 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ org.http4k http4k-core - 3.260.0 + 3.265.0 org.apache.commons diff --git a/src/main/kotlin/starter/KotlinStarter.kt b/src/main/kotlin/starter/KotlinStarter.kt index b0eab04..4106225 100644 --- a/src/main/kotlin/starter/KotlinStarter.kt +++ b/src/main/kotlin/starter/KotlinStarter.kt @@ -1,55 +1,10 @@ package starter -import org.http4k.core.then -import org.http4k.filter.ServerFilters -import org.http4k.routing.ResourceLoader -import org.http4k.routing.RoutingHttpHandler -import org.http4k.routing.routes -import org.http4k.routing.static -import org.http4k.server.SunHttp -import org.http4k.server.asServer import org.koin.core.context.startKoin -import org.koin.dsl.bind -import org.koin.dsl.module -import org.koin.dsl.onClose -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import starter.routes.IndexRouteSupplier -import starter.routes.RouteSupplier -import starter.routes.ZipRouteSupplier -import starter.routes.toRouter -import starter.templates.* - -val mainModule = module { - single(createdAtStart = true) { - get().info("Starting on http://localhost:7000") - get().asServer(SunHttp(7000)).start() - } onClose { it?.stop() } - - single { Config().load() } - single { LoggerFactory.getLogger("Starter") } - single { Views(get(), get()) } - single { ProjectZip(getAll()) } -} - -val templateModule = module { - single { PomTemplate(get()) } bind Template::class - single { MainTemplate(get()) } bind Template::class - single { LogbackTemplate(get()) } bind Template::class - single { GitignoreTemplate(get()) } bind Template::class -} - -val routesModule = module { - single { IndexRouteSupplier(get()) } bind RouteSupplier::class - single { ZipRouteSupplier(get(), get()) } bind RouteSupplier::class - single { - ServerFilters.CatchAll().then( - routes( - static(ResourceLoader.Classpath("/assets")), - getAll().toRouter() - )) - } -} +import starter.modules.mainModule +import starter.modules.pebbleModule +import starter.modules.routesModule +import starter.modules.templateModule fun main() { startKoin { diff --git a/src/main/kotlin/starter/Config.kt b/src/main/kotlin/starter/config/Config.kt similarity index 97% rename from src/main/kotlin/starter/Config.kt rename to src/main/kotlin/starter/config/Config.kt index 43989ea..d265a02 100644 --- a/src/main/kotlin/starter/Config.kt +++ b/src/main/kotlin/starter/config/Config.kt @@ -1,6 +1,7 @@ -package starter +package starter.config import com.electronwill.nightconfig.core.file.FileConfig +import starter.* import com.electronwill.nightconfig.core.Config as NightConfig data class StarterConfig( diff --git a/src/main/kotlin/starter/modules/MainModule.kt b/src/main/kotlin/starter/modules/MainModule.kt new file mode 100644 index 0000000..f485ed2 --- /dev/null +++ b/src/main/kotlin/starter/modules/MainModule.kt @@ -0,0 +1,24 @@ +package starter.modules + +import org.http4k.routing.RoutingHttpHandler +import org.http4k.server.SunHttp +import org.http4k.server.asServer +import org.koin.dsl.module +import org.koin.dsl.onClose +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import starter.ProjectZip +import starter.config.Config +import starter.views.Views + +val mainModule = module { + single(createdAtStart = true) { + get().info("Starting on http://localhost:7000") + get().asServer(SunHttp(7000)).start() + } onClose { it?.stop() } + + single { Config().load() } + single { LoggerFactory.getLogger("Starter") } + single { Views(get(), get()) } + single { ProjectZip(getAll()) } +} diff --git a/src/main/kotlin/starter/PebbleModule.kt b/src/main/kotlin/starter/modules/PebbleModule.kt similarity index 97% rename from src/main/kotlin/starter/PebbleModule.kt rename to src/main/kotlin/starter/modules/PebbleModule.kt index b7851f2..c8cc9f4 100644 --- a/src/main/kotlin/starter/PebbleModule.kt +++ b/src/main/kotlin/starter/modules/PebbleModule.kt @@ -1,4 +1,4 @@ -package starter +package starter.modules import com.mitchellbosecke.pebble.extension.escaper.SafeString import com.mitchellbosecke.pebble.template.EvaluationContext @@ -6,6 +6,7 @@ import com.mitchellbosecke.pebble.template.PebbleTemplate import org.intellij.lang.annotations.Language import org.koin.dsl.bind import org.koin.dsl.module +import starter.Dependency import starter.utils.PebbleEngineBuilder import starter.utils.PebbleEngineBuilder.CacheType.ConcurrentMap import starter.utils.PebbleFunction diff --git a/src/main/kotlin/starter/modules/RoutesModule.kt b/src/main/kotlin/starter/modules/RoutesModule.kt new file mode 100644 index 0000000..2d5eeeb --- /dev/null +++ b/src/main/kotlin/starter/modules/RoutesModule.kt @@ -0,0 +1,25 @@ +package starter.modules + +import org.http4k.core.then +import org.http4k.filter.ServerFilters +import org.http4k.routing.ResourceLoader +import org.http4k.routing.routes +import org.http4k.routing.static +import org.koin.dsl.bind +import org.koin.dsl.module +import starter.routes.IndexRouteSupplier +import starter.routes.RouteSupplier +import starter.routes.ZipRouteSupplier +import starter.routes.toRouter + +val routesModule = module { + single { IndexRouteSupplier(get()) } bind RouteSupplier::class + single { ZipRouteSupplier(get(), get()) } bind RouteSupplier::class + single { + ServerFilters.CatchAll().then( + routes( + static(ResourceLoader.Classpath("/assets")), + getAll().toRouter() + )) + } +} diff --git a/src/main/kotlin/starter/modules/TemplateModule.kt b/src/main/kotlin/starter/modules/TemplateModule.kt new file mode 100644 index 0000000..ec23174 --- /dev/null +++ b/src/main/kotlin/starter/modules/TemplateModule.kt @@ -0,0 +1,12 @@ +package starter.modules + +import org.koin.dsl.bind +import org.koin.dsl.module +import starter.templates.* + +val templateModule = module { + single { PomTemplate(get()) } bind Template::class + single { MainTemplate(get()) } bind Template::class + single { LogbackTemplate(get()) } bind Template::class + single { GitignoreTemplate(get()) } bind Template::class +} diff --git a/src/main/kotlin/starter/routes/IndexRouteSupplier.kt b/src/main/kotlin/starter/routes/IndexRouteSupplier.kt index a498584..b6e10d6 100644 --- a/src/main/kotlin/starter/routes/IndexRouteSupplier.kt +++ b/src/main/kotlin/starter/routes/IndexRouteSupplier.kt @@ -4,8 +4,7 @@ import org.http4k.core.Method import org.http4k.core.Response import org.http4k.core.Status import org.http4k.routing.bind -import starter.StarterConfig -import starter.Views +import starter.views.Views class IndexRouteSupplier(private val views: Views) : RouteSupplier { override fun get() = "/" bind Method.GET to { diff --git a/src/main/kotlin/starter/routes/ZipRouteSupplier.kt b/src/main/kotlin/starter/routes/ZipRouteSupplier.kt index 3e7444d..2d5f35e 100644 --- a/src/main/kotlin/starter/routes/ZipRouteSupplier.kt +++ b/src/main/kotlin/starter/routes/ZipRouteSupplier.kt @@ -8,15 +8,15 @@ import org.http4k.core.with import org.http4k.routing.bind import starter.Project import starter.ProjectZip -import starter.StarterConfig +import starter.config.StarterConfig import starter.extensions.attachment import starter.extensions.badRequest import starter.extensions.ok import java.io.ByteArrayInputStream class ZipRouteSupplier( - private val conf: StarterConfig, - private val projectZip: ProjectZip, + private val conf: StarterConfig, + private val projectZip: ProjectZip, ) : RouteSupplier { override fun get() = "/" bind Method.POST to { req -> diff --git a/src/main/kotlin/starter/Views.kt b/src/main/kotlin/starter/views/Views.kt similarity index 86% rename from src/main/kotlin/starter/Views.kt rename to src/main/kotlin/starter/views/Views.kt index 5e20bdc..6fe4267 100644 --- a/src/main/kotlin/starter/Views.kt +++ b/src/main/kotlin/starter/views/Views.kt @@ -1,6 +1,7 @@ -package starter +package starter.views import com.mitchellbosecke.pebble.PebbleEngine +import starter.config.StarterConfig import starter.utils.render class Views(private val engine: PebbleEngine, config: StarterConfig) {