Project Description
Server-side Swift with an HTTP server and an SQL database

This project provides a simple HTTP server written in Swift based on libevent. Similarly to node.js, a server can be implemented as follows:

let server = HTTPServer(port: 8080) { request, response in
    print("method: \(request.method)")
    print("URI: \(request.uri)")
    if request.uri == "/file" {
        response.sendFile(200, "OK", "text/plain", "test.txt")
    } else {
        response.sendText(200, "OK", "text/plain", "OK: " + request.uri)
    }
}
server.listen()

You can host web apps for free on Amazon's EC2 (in the free tier you get 750 hours/month). Set up an Ubuntu micro instance and download and extract the swiftserver.tgz file. Download the Swift development snapshot for Linux (Ubuntu 14) from swift.org. Rename the extracted directory (it must be in the dev subdirectory) to swift and type

sudo ./setup.sh

This will install the necessary packages and create a symbolic link to the Swift compiler in /usr/local/bin. Now type

cd server
make
LD_LIBRARY_PATH=. ./server1

The server is now up and running. Don't forget to allow incoming traffic (in Security groups/Inbound).

(The source code will be released in a couple days since it has to be refactored and embellished.)

Last edited Dec 21, 2015 at 5:59 PM by slonzok, version 4