summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-01-18 22:42:57 +0100
committerMS <ms@taler.net>2023-01-18 22:42:57 +0100
commita8413e5315b078a1833beb597de400ad1dbfe2ee (patch)
treeff9f023d60e083387e900bfe981cee794e928a3b /sandbox/src/main/kotlin/tech/libeufin
parentbb485263833445d93ae2d5bba71b55bfdc18367a (diff)
downloadlibeufin-a8413e5315b078a1833beb597de400ad1dbfe2ee.tar.gz
libeufin-a8413e5315b078a1833beb597de400ad1dbfe2ee.tar.bz2
libeufin-a8413e5315b078a1833beb597de400ad1dbfe2ee.zip
Falling back to IPv4, when IPv6 isn't supported.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt51
1 files changed, 16 insertions, 35 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 48f22ca9..3bfce37a 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -60,7 +60,6 @@ import org.w3c.dom.Document
import startServer
import tech.libeufin.util.*
import java.math.BigDecimal
-import java.net.BindException
import java.net.URL
import java.security.interfaces.RSAPublicKey
import javax.xml.bind.JAXBContext
@@ -355,8 +354,11 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
WITH_AUTH = auth
setLogLevel(logLevel)
if (WITH_AUTH && adminPassword == null) {
- System.err.println("Error: auth is enabled, but env LIBEUFIN_SANDBOX_ADMIN_PASSWORD is not."
- + " (Option --no-auth exists for tests)")
+ System.err.println(
+ "Error: auth is enabled, but env " +
+ "LIBEUFIN_SANDBOX_ADMIN_PASSWORD is not."
+ + " (Option --no-auth exists for tests)"
+ )
exitProcess(1)
}
execThrowableOrTerminate { dbCreateTables(getDbConnFromEnv(SANDBOX_DB_ENV_VAR_NAME)) }
@@ -376,7 +378,16 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
}
SMS_TAN_CMD = smsTan
EMAIL_TAN_CMD = emailTan
- serverMain(port, localhostOnly, ipv4Only)
+
+ logger.info("Starting Sandbox on port ${this.port}")
+ startServerWithIPv4Fallback(
+ options = StartServerOptions(
+ ipv4OnlyOpt = this.ipv4Only,
+ localhostOnlyOpt = this.localhostOnly,
+ portOpt = this.port
+ ),
+ app = sandboxApp
+ )
}
}
@@ -1606,34 +1617,4 @@ val sandboxApp: Application.() -> Unit = {
}
}
}
-}
-
-fun serverMain(port: Int, localhostOnly: Boolean, ipv4Only: Boolean) {
- val server = embeddedServer(
- Netty,
- environment = applicationEngineEnvironment{
- connector {
- this.port = port
- this.host = if (localhostOnly) "127.0.0.1" else "0.0.0.0"
- }
- if (!ipv4Only) connector {
- this.port = port
- this.host = if (localhostOnly) "[::1]" else "[::]"
- }
- // parentCoroutineContext = Dispatchers.Main
- module(sandboxApp)
- },
- configure = {
- connectionGroupSize = 1
- workerGroupSize = 1
- callGroupSize = 1
- }
- )
- logger.info("LibEuFin Sandbox running on port $port")
- try {
- server.start(wait = true)
- } catch (e: BindException) {
- logger.error(e.message)
- exitProcess(1)
- }
-}
+} \ No newline at end of file