Add CORS config
This commit is contained in:
parent
cf52525926
commit
04ded6de17
@ -3,3 +3,4 @@ MYSQL_DATABASE=
|
||||
MYSQL_USER=
|
||||
MYSQL_PASSWORD=
|
||||
JWT_SECRET=
|
||||
CORS=false
|
||||
@ -10,6 +10,7 @@ database:
|
||||
server:
|
||||
host: 0.0.0.0
|
||||
port: 8081
|
||||
cors: ${CORS:-true}
|
||||
|
||||
jwt:
|
||||
secret: ${JWT_SECRET}
|
||||
|
||||
@ -19,7 +19,6 @@ import org.kodein.di.generic.singleton
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.sql.DataSource
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
val kodein = Kodein {
|
||||
import(serviceModule)
|
||||
@ -57,7 +56,7 @@ fun serve(kodein: Kodein) {
|
||||
|
||||
|
||||
fun Application.module() {
|
||||
loadFeatures()
|
||||
loadFeatures(kodein)
|
||||
|
||||
log.debug(kodein.container.tree.bindings.description())
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ val configurationModule = Kodein.Module(name = "Configuration") {
|
||||
}
|
||||
|
||||
data class DatabaseConfig(val host: String, val port: Int, val name: String, val username: String, val password: Masked)
|
||||
data class ServerConfig(val host: String, val port: Int)
|
||||
data class ServerConfig(val host: String, val port: Int, val cors: Boolean)
|
||||
data class JwtConfig(val secret: Masked, val auth: JwtValidity, val refresh: JwtValidity)
|
||||
data class JwtValidity(val validity: Long, val unit: TimeUnit)
|
||||
data class Config(val database: DatabaseConfig, val server: ServerConfig, val jwt: JwtConfig)
|
||||
|
||||
@ -2,9 +2,14 @@ package be.vandewalleh.features
|
||||
|
||||
import be.vandewalleh.auth.authenticationModule
|
||||
import io.ktor.application.*
|
||||
import org.kodein.di.Kodein
|
||||
import org.kodein.di.generic.instance
|
||||
|
||||
fun Application.loadFeatures() {
|
||||
corsFeature()
|
||||
fun Application.loadFeatures(kodein: Kodein) {
|
||||
val config by kodein.instance<Config>()
|
||||
if (config.server.cors) {
|
||||
corsFeature()
|
||||
}
|
||||
contentNegotiationFeature()
|
||||
authenticationModule()
|
||||
handleErrors()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user