Yokan / rebuild
Course 1 8624561

ExtensionServerPorts.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/extensions/mihon/ExtensionServerPorts.kt

implementation17 lines
1package eu.friedcutlet.yokan.services.extensions.mihon23/**4 * Returns [preferred] when it can still be bound on the loopback interface, otherwise an5 * OS-assigned free port (loopback bind to port 0). The default proxy port 8080 is commonly6 * taken by other local software, so callers must treat the returned port as authoritative7 * and persist the resulting proxy URL.8 */9internal expect fun findAvailableExtensionServerPort(preferred: Int): Int1011internal fun extensionServerPortFromUrl(url: String?, fallback: Int = 8080): Int =12    Regex(""":(\d{1,5})(?:/|$)""").find(url.orEmpty())13        ?.groupValues14        ?.getOrNull(1)15        ?.toIntOrNull()16        ?.takeIf { it in 1..65535 }17        ?: fallback18

Search chapters, reference and source filenames.