Created
October 31, 2016 21:51
-
-
Save mramsden/1dfb1b901907c558032a905944fe6dc8 to your computer and use it in GitHub Desktop.
A simple Kitua app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Kitura | |
import HeliumLogger | |
// Initialize HeliumLogger | |
HeliumLogger.use() | |
// Create new router | |
let router = Router() | |
// Handle HTTP GET requests to / | |
router.get("/") { request, response, next in | |
response.send("Hello world") | |
next() | |
} | |
// Resolve the port that we want the server to listen on. | |
let port: Int | |
let defaultPort = 8080 | |
if let requestedPort = ProcessInfo.processInfo.environment["PORT"] { | |
port = Int(requestedPort) ?? defaultPort | |
} else { | |
port = defaultPort | |
} | |
// Add an HTTP server and connect it to the router | |
Kitura.addHTTPServer(onPort: port, with: router) | |
// Start the Kitura runloop (this call never returns) | |
Kitura.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment