Add configuration environment
This commit is contained in:
parent
312b4b6769
commit
fc7fa6b5f7
21
api/resources/application.dev.yaml
Normal file
21
api/resources/application.dev.yaml
Normal 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
|
||||||
|
|
||||||
@ -1,5 +1,3 @@
|
|||||||
env: staging
|
|
||||||
|
|
||||||
database:
|
database:
|
||||||
host: ${MYSQL_HOST}
|
host: ${MYSQL_HOST}
|
||||||
port: 3306
|
port: 3306
|
||||||
@ -13,7 +11,7 @@ server:
|
|||||||
cors: ${CORS:-true}
|
cors: ${CORS:-true}
|
||||||
|
|
||||||
jwt:
|
jwt:
|
||||||
secret: ${JWT_SECRET}
|
secret: ${JWT_SECRET} # Can be generated with `openssl rand -base64 32`
|
||||||
auth:
|
auth:
|
||||||
validity: 1
|
validity: 1
|
||||||
unit: HOURS
|
unit: HOURS
|
||||||
@ -8,7 +8,8 @@
|
|||||||
<appender-ref ref="STDOUT"/>
|
<appender-ref ref="STDOUT"/>
|
||||||
</root>
|
</root>
|
||||||
<logger name="me.liuwj.ktorm.database" level="INFO"/>
|
<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="org.eclipse.jetty" level="INFO"/>
|
||||||
<logger name="io.netty" level="INFO"/>
|
<logger name="io.netty" level="INFO"/>
|
||||||
|
<logger name="org.flywaydb.core" level="INFO"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -32,7 +32,7 @@ fun main() {
|
|||||||
val config by kodein.instance<Config>()
|
val config by kodein.instance<Config>()
|
||||||
val logger by kodein.instance<Logger>()
|
val logger by kodein.instance<Logger>()
|
||||||
logger.info("Running application with configuration $config")
|
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>()
|
val migration by kodein.instance<Migration>()
|
||||||
migration.migrate()
|
migration.migrate()
|
||||||
serve(kodein)
|
serve(kodein)
|
||||||
@ -58,20 +58,8 @@ fun serve(kodein: Kodein) {
|
|||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
loadFeatures(kodein)
|
loadFeatures(kodein)
|
||||||
|
|
||||||
log.debug(kodein.container.tree.bindings.description())
|
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
registerRoutes(kodein)
|
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) }
|
|
||||||
}
|
|
||||||
@ -9,6 +9,7 @@ import org.kodein.di.Kodein
|
|||||||
import org.kodein.di.generic.bind
|
import org.kodein.di.generic.bind
|
||||||
import org.kodein.di.generic.instance
|
import org.kodein.di.generic.instance
|
||||||
import org.kodein.di.generic.singleton
|
import org.kodein.di.generic.singleton
|
||||||
|
import org.kodein.di.generic.with
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.sql.DataSource
|
import javax.sql.DataSource
|
||||||
|
|
||||||
@ -16,7 +17,11 @@ import javax.sql.DataSource
|
|||||||
* [Kodein] controller module containing the app configuration
|
* [Kodein] controller module containing the app configuration
|
||||||
*/
|
*/
|
||||||
val configurationModule = Kodein.Module(name = "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 = "auth") with singleton { configureAuthJwt(this.kodein) }
|
||||||
bind<SimpleJWT>(tag = "refresh") with singleton { configureRefreshJwt(this.kodein) }
|
bind<SimpleJWT>(tag = "refresh") with singleton { configureRefreshJwt(this.kodein) }
|
||||||
bind<DataSource>() with singleton { configureDatasource(this.kodein) }
|
bind<DataSource>() with singleton { configureDatasource(this.kodein) }
|
||||||
@ -58,4 +63,4 @@ private fun configureDatasource(kodein: Kodein): DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return HikariDataSource(hikariConfig)
|
return HikariDataSource(hikariConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user