Selaa lähdekoodia

port set with env

herlanS_ 3 vuotta sitten
vanhempi
commit
3df2e7a9d1

+ 1 - 0
.gitignore

@@ -5,6 +5,7 @@ target/
 !**/src/main/**
 !**/src/test/**
 *.zip
+conf/general.ini
 
 ### STS ###
 .apt_generated

+ 2 - 0
conf/general-example.ini

@@ -0,0 +1,2 @@
+[server]
+port = 9090

+ 0 - 2
conf/general.ini

@@ -1,2 +0,0 @@
-[server]
-port = 9091

+ 15 - 10
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/IpPhoneBridgeApplication.kt

@@ -9,7 +9,6 @@ import org.springframework.scheduling.annotation.EnableScheduling
 import java.io.File
 import java.io.Serializable
 import java.util.*
-import kotlin.system.exitProcess
 
 
 @SpringBootApplication
@@ -19,17 +18,23 @@ class IpPhoneBridgeApplication
 fun main(args: Array<String>) {
     TimeZone.setDefault(TimeZone.getTimeZone("Asia/Jakarta"))
     val properties = Properties()
-    val confFile = File("conf/general.ini")
-    if (confFile.exists()) {
-        val ini = Wini(File("conf/general.ini"))
-        properties["server.port"] = ini.get("server", "port")
-    } else {
-        properties["server.port"] = System.getenv("PORT")
-    }
-    if (properties["server.port"] == null) {
-        exitProcess(1)
+    val iniFIle = File("conf/general.ini")
+
+    properties["server.port"] = when {
+        System.getenv("PORT") != null -> {
+            System.getenv("PORT")
+        }
+        iniFIle.exists() -> {
+            val ini = Wini(iniFIle)
+            ini.get("server", "port") ?: "9090"
+        }
+        else -> {
+            "9090"
+        }
     }
 
+
+
     val sApp = SpringApplication(IpPhoneBridgeApplication::class.java)
 
     sApp.setDefaultProperties(properties)