Created
February 18, 2018 07:39
-
-
Save mczachurski/972a9ddc5fb0307d82fd31e6b2a74842 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 PerfectHTTP | |
import PerfectHTTPServer | |
import PerfectLib | |
import Dip | |
import TaskerServerLib | |
import Configuration | |
// Read configuration file. | |
let configurationManager = ConfigurationManager() | |
.load(file: "configuration.json", relativeFrom: .pwd) | |
.load(.environmentVariables) | |
.load(.commandLineArguments) | |
let configuration = configurationManager.build() | |
// Configure dependency injection. | |
let container = DependencyContainer() | |
container.configure(withConfiguration: configuration) | |
// Initialize all controllers. | |
let controllers = container.resolveAllControllers() | |
// Routes and handlers. | |
var routes = Routes() | |
routes.configure(basedOnControllers: controllers) | |
do { | |
// Launch the HTTP server. | |
try HTTPServer.launch( | |
.server(name: configuration.serverName, port: configuration.serverPort, routes: routes)) | |
} catch { | |
fatalError("\(error)") // fatal error launching one of the servers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment