mirror of
https://github.com/jlengrand/pluckr.git
synced 2026-03-10 08:41:17 +00:00
Adds various confs for testing
This commit is contained in:
@@ -40,6 +40,7 @@ dependencies {
|
||||
implementation("io.ktor:ktor-server-metrics-micrometer:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-cors:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-auth:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-sessions-jvm:2.1.0")
|
||||
|
||||
implementation("org.mindrot:jbcrypt:0.4")
|
||||
|
||||
@@ -51,7 +52,8 @@ dependencies {
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
|
||||
implementation("org.postgresql:postgresql:$postgresqlVersion")
|
||||
implementation("net.postgis:postgis-jdbc:$postgisVersion")
|
||||
implementation("io.ktor:ktor-server-sessions-jvm:2.1.0")
|
||||
implementation("com.h2database:h2:2.1.214")
|
||||
|
||||
|
||||
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.ktor.server.netty.*
|
||||
import io.ktor.server.plugins.callloging.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.sessions.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import nl.lengrand.pluckr.plugins.configureRouting
|
||||
@@ -19,8 +20,21 @@ import org.jetbrains.exposed.sql.addLogger
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
fun Application.module() {
|
||||
val env = environment.config.propertyOrNull("ktor.environment")?.getString()
|
||||
println("Running in the $env environment")
|
||||
|
||||
val database = initDb()
|
||||
routing {
|
||||
get("/api/environment") {
|
||||
call.respondText(env?: "null")
|
||||
}
|
||||
}
|
||||
|
||||
val database = initDb(
|
||||
environment.config.property("ktor.database.url").getString(),
|
||||
environment.config.property("ktor.database.driver").getString(),
|
||||
environment.config.property("ktor.database.user").getString(),
|
||||
environment.config.property("ktor.database.password").getString(),
|
||||
)
|
||||
|
||||
install(Sessions) {
|
||||
cookie<UserSession>("user_session", SessionStorageMemory()) {
|
||||
@@ -63,26 +77,25 @@ fun Application.module() {
|
||||
configureRouting(database)
|
||||
}
|
||||
|
||||
fun initDb(): Database {
|
||||
val database = Database.connect(
|
||||
"jdbc:postgresql://localhost:5432/pluckr", driver = "org.postgresql.Driver",
|
||||
user = "pluckr", password = System.getenv("PLUCKR_PASSWORD")
|
||||
)
|
||||
fun initDb(url: String, driver: String, user: String, password: String): Database {
|
||||
val database = Database.connect(url, driver, user , password )
|
||||
|
||||
transaction {
|
||||
transaction(database) {
|
||||
addLogger(StdOutSqlLogger)
|
||||
SchemaUtils.create(Trees, Users)
|
||||
}
|
||||
return database
|
||||
}
|
||||
|
||||
fun main() {
|
||||
embeddedServer(
|
||||
Netty,
|
||||
port = 9090,
|
||||
host = "0.0.0.0"
|
||||
){
|
||||
module()
|
||||
}
|
||||
.start(wait = true)
|
||||
}
|
||||
//fun main() {
|
||||
// embeddedServer(
|
||||
// Netty,
|
||||
// port = 9090,
|
||||
// host = "0.0.0.0"
|
||||
// ){
|
||||
// module()
|
||||
// }
|
||||
// .start(wait = true)
|
||||
//}
|
||||
|
||||
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
||||
|
||||
16
src/main/resources/application.conf
Normal file
16
src/main/resources/application.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
ktor {
|
||||
environment = test
|
||||
|
||||
deployment {
|
||||
port = 8080
|
||||
}
|
||||
application {
|
||||
modules = [ nl.lengrand.pluckr.ApplicationKt.module ]
|
||||
}
|
||||
database {
|
||||
url = "jdbc:h2:mem:test"
|
||||
driver = "org.h2.Driver"
|
||||
user = "pluckr"
|
||||
password = ${PLUCKR_PASSWORD}
|
||||
}
|
||||
}
|
||||
16
src/main/resources/application.dev.conf
Normal file
16
src/main/resources/application.dev.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
ktor {
|
||||
environment = dev
|
||||
|
||||
deployment {
|
||||
port = 8080
|
||||
}
|
||||
application {
|
||||
modules = [ nl.lengrand.pluckr.ApplicationKt.module ]
|
||||
}
|
||||
database{
|
||||
url = "jdbc:postgresql://localhost:5432/pluckr"
|
||||
driver = "org.postgresql.Driver"
|
||||
user = "pluckr"
|
||||
password = ${PLUCKR_PASSWORD}
|
||||
}
|
||||
}
|
||||
17
src/main/resources/application.test.conf
Normal file
17
src/main/resources/application.test.conf
Normal file
@@ -0,0 +1,17 @@
|
||||
ktor {
|
||||
environment = test
|
||||
|
||||
deployment {
|
||||
port = 8080
|
||||
}
|
||||
application {
|
||||
modules = [ nl.lengrand.pluckr.ApplicationKt.module ]
|
||||
}
|
||||
|
||||
database{
|
||||
url = "jdbc:h2:mem:test"
|
||||
driver = "org.h2.Driver"
|
||||
user = "pluckr"
|
||||
password = ${PLUCKR_PASSWORD}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user