diff --git a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/ApiTool.kt b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/ApiTool.kt index 0294f9e..2c790c1 100644 --- a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/ApiTool.kt +++ b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/view/ApiTool.kt @@ -10,10 +10,12 @@ import okhttp3.internal.EMPTY_REQUEST class ApiTool { companion object { const val JSON = "application/json" - val apiRoot = System.getProperty("pairgoth.api.url").let { base -> - if (base.endsWith('/')) "${base}api/" - else "${base}/api/" - } + val apiRoot = + (System.getProperty("pairgoth.api.url") ?: System.getProperty("pairgoth.webapp.url")) + .let { base -> + if (base.endsWith('/')) "${base}api/" + else "${base}/api/" + } } private val client = OkHttpClient() private fun prepare(url: String) = Request.Builder().url("$apiRoot$url").header("Accept", JSON) diff --git a/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt b/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt index f0223ef..e2e3c93 100644 --- a/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt +++ b/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt @@ -35,7 +35,11 @@ import java.util.regex.Pattern fun main(vararg args: String) { try { + // read default properties and provided ones, if any + readProperties() + // extract war files from main archive extractWarFiles() + // launch web server launchServer() } catch (t: Throwable) { t.printStackTrace(System.err) @@ -45,6 +49,30 @@ fun main(vararg args: String) { private val tmp = System.getProperty("java.io.tmpdir") private val version = "1.0-SNAPSHOT" // TODO CB +private fun readProperties() { + val defaultProps = getResource("/server.default.properties") ?: throw Error("missing default server properties") + defaultProps.openStream().use { + serverProps.load(InputStreamReader(it, StandardCharsets.UTF_8)) + } + val properties = File("./pairgoth.properties") + if (properties.exists()) { + serverProps.load(FileReader(properties)) + serverProps.entries.forEach { entry -> + val property = entry.key as String + val value = entry.value as String + if (!property.startsWith("webapp.ssl.")) { + // do not propagate ssl properties further + System.setProperty("pairgoth.$property", value) + } + } + } + // we want colorized output on linux + if (System.getProperty("os.name") == "Linux") + { + System.setProperty("org.eclipse.jetty.logging.appender.MESSAGE_ESCAPE", "false"); + } +} + private fun extractWarFiles() { // val jarLocation = object{}::class.java.protectionDomain.codeSource.location // prepare output directory @@ -66,11 +94,11 @@ private fun extractWarFiles() { } } } - private val mainClass = object{}::class.java.enclosingClass private val jarPath = mainClass.protectionDomain.codeSource.location.path.let { URLDecoder.decode(it, "UTF-8") } private val serverProps = Properties() private fun getResource(resource: String) = mainClass.getResource(resource) + private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let { property -> val url = property.replace("\$jar", jarPath) if (!Resource.newResource(url).exists()) throw Error("resource not found: $url") @@ -78,10 +106,6 @@ private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let } ?: throw Error("missing property: $key") private fun launchServer() { - - // read default properties and provided ones, if any - readProperties() - // create webapps contexts val webAppContexts = mutableListOf() val mode = serverProps["mode"] ?: throw Error("missing property: mode") @@ -125,26 +149,6 @@ private fun createContext(webapp: String, contextPath: String) = WebAppContext() context.contextPath = contextPath } -private fun readProperties() { - val defaultProps = getResource("/server.default.properties") ?: throw Error("missing default server properties") - defaultProps.openStream().use { - serverProps.load(InputStreamReader(it, StandardCharsets.UTF_8)) - } - val properties = File("./pairgoth.properties") - if (properties.exists()) { - serverProps.load(FileReader(properties)) - serverProps.entries.forEach { entry -> - val property = entry.key as String - val value = entry.value as String - if (!property.startsWith("webapp.ssl.")) { - // do not propagate ssl properties further - } else { - System.setProperty("pairgoth.$property", value) - } - } - } -} - private fun buildSecureConnector(server: Server, port: Int): ServerConnector { // set up http/2 val httpConfig = HttpConfiguration().apply {