I would like my iOS app to host a small HTTP server, such that other app users can download files from the host.
I've tried using both Telegraph and Swifter. I can get the server to work on localhost
but I can't figure out how to
- Get the device's IP where the server is hosted
- Configure it to host publicly at this IP
Telegram Code
let server = Server()
try! server.start(port: 9000)
let demoBundleURL = Bundle.main.url(forResource: "Demo", withExtension: nil)!
server.serveDirectory(demoBundleURL, "/demo")
server.route(.GET, "status") { (.ok, "Server is running") }
SWIFTER CODE
let server = HttpServer()
server["/"] = scopes {
html {
body {
center {
img { src = "https://swift.org/assets/images/swift.svg" }
}
}
}
}
server["/files/:path"] = directoryBrowser("/")
let semaphore = DispatchSemaphore(value: 0)
do {
try server.start(9080, forceIPv4: true)
print("Server has started ( port = \(try server.port()) ). Try to connect now...")
semaphore.wait()
} catch {
print("Server start error: \(error)")
semaphore.signal()
}