Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Created February 18, 2018 07:39
Show Gist options
  • Save mczachurski/972a9ddc5fb0307d82fd31e6b2a74842 to your computer and use it in GitHub Desktop.
Save mczachurski/972a9ddc5fb0307d82fd31e6b2a74842 to your computer and use it in GitHub Desktop.
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