Add configuration environment

This commit is contained in:
Hubert Van De Walle 2020-06-14 16:44:24 +02:00
parent 312b4b6769
commit fc7fa6b5f7
5 changed files with 32 additions and 19 deletions

View File

@ -0,0 +1,21 @@
database:
host: localhost
port: 3306
name: notes
username: notes
password: notes
server:
host: 127.0.0.1
port: 8081
cors: true
jwt:
secret: 9Io9kvgIedOcLdUvKl31OKf51jdTZcFHJFgqvEpfJuI= # Can be generated with `openssl rand -base64 32`
auth:
validity: 1
unit: HOURS
refresh:
validity: 15
unit: DAYS

View File

@ -1,5 +1,3 @@
env: staging
database:
host: ${MYSQL_HOST}
port: 3306
@ -13,7 +11,7 @@ server:
cors: ${CORS:-true}
jwt:
secret: ${JWT_SECRET}
secret: ${JWT_SECRET} # Can be generated with `openssl rand -base64 32`
auth:
validity: 1
unit: HOURS

View File

@ -8,7 +8,8 @@
<appender-ref ref="STDOUT"/>
</root>
<logger name="me.liuwj.ktorm.database" level="INFO"/>
<logger name="com.zaxxer.hikari.pool.HikariPool" level="INFO"/>
<logger name="com.zaxxer.hikari" level="INFO"/>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
<logger name="org.flywaydb.core" level="INFO"/>
</configuration>

View File

@ -32,7 +32,7 @@ fun main() {
val config by kodein.instance<Config>()
val logger by kodein.instance<Logger>()
logger.info("Running application with configuration $config")
logger.info("Kodein bindings\n${kodein.container.tree.bindings.description()}")
logger.debug("Kodein bindings\n${kodein.container.tree.bindings.description()}")
val migration by kodein.instance<Migration>()
migration.migrate()
serve(kodein)
@ -58,20 +58,8 @@ fun serve(kodein: Kodein) {
fun Application.module() {
loadFeatures(kodein)
log.debug(kodein.container.tree.bindings.description())
routing {
registerRoutes(kodein)
}
val root = feature(Routing)
val allRoutes = allRoutes(root)
allRoutes.forEach {
println(it.toString())
}
}
fun allRoutes(root: Route): List<Route> {
return listOf(root) + root.children.flatMap { allRoutes(it) }
}

View File

@ -9,6 +9,7 @@ import org.kodein.di.Kodein
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.singleton
import org.kodein.di.generic.with
import java.util.concurrent.TimeUnit
import javax.sql.DataSource
@ -16,7 +17,11 @@ import javax.sql.DataSource
* [Kodein] controller module containing the app configuration
*/
val configurationModule = Kodein.Module(name = "Configuration") {
bind() from singleton { ConfigLoader().loadConfigOrThrow<Config>("/application.yaml") }
constant("config file") with "/application.dev.yaml" // FIXME
bind() from singleton {
val configFile by this.kodein.instance<String>(tag = "config file")
ConfigLoader().loadConfigOrThrow<Config>(configFile)
}
bind<SimpleJWT>(tag = "auth") with singleton { configureAuthJwt(this.kodein) }
bind<SimpleJWT>(tag = "refresh") with singleton { configureRefreshJwt(this.kodein) }
bind<DataSource>() with singleton { configureDatasource(this.kodein) }
@ -58,4 +63,4 @@ private fun configureDatasource(kodein: Kodein): DataSource {
}
return HikariDataSource(hikariConfig)
}
}