File tree Expand file tree Collapse file tree 4 files changed +21
-3
lines changed
kotlin/me/moallemi/kmpshowcase/server Expand file tree Collapse file tree 4 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1+ package me.moallemi.kmpshowcase.server
2+
3+ import io.ktor.application.Application
4+
5+ private val Application .envType get() = environment.config.property(" ktor.environment" ).getString()
6+ val Application .isDev get() = envType == " dev"
7+ val Application .isProd get() = envType == " prod"
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package me.moallemi.kmpshowcase.server
22
33import io.ktor.application.Application
44import io.ktor.application.install
5+ import io.ktor.features.CORS
56import io.ktor.features.ContentNegotiation
67import io.ktor.http.content.resources
78import io.ktor.http.content.static
@@ -17,6 +18,12 @@ fun Application.module(testing: Boolean = false) {
1718 json()
1819 }
1920
21+ if (isDev) {
22+ install(CORS ) {
23+ anyHost()
24+ }
25+ }
26+
2027 routing {
2128 home()
2229 apiV1()
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import io.ktor.request.host
66import io.ktor.request.port
77
88fun ApplicationCall.baseUrl () =
9- if (request.host() != " 0.0.0.0" ) {
9+ if (request.host() !in listOf ( " 0.0.0.0" , " localhost " ) ) {
1010 " https://${request.host()} "
1111 } else {
1212 " ${request.origin.scheme} ://${request.host()} :${request.port()} "
Original file line number Diff line number Diff line change 11ktor {
22 deployment {
3- port = 8080
3+ port = 9090
44 port = ${?PORT}
55 }
6+
7+ environment = dev
8+ environment = ${?KTOR_ENV}
9+
610 application {
7- modules = [ me.moallemi.kmpshowcase.server.ApplicationKt .module ]
11+ modules = [ me.moallemi.kmpshowcase.server.ServerAppKt .module ]
812 }
913}
You can’t perform that action at this time.
0 commit comments