23 lines
776 B
Swift
Executable File
23 lines
776 B
Swift
Executable File
import Vapor
|
|
|
|
var keyManager: KeyManagement!
|
|
|
|
// configures your application
|
|
public func configure(_ app: Application) throws {
|
|
app.http.server.configuration.port = 6003
|
|
|
|
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
|
let keyFile = storageFolder.appendingPathComponent("device.key")
|
|
let deviceKey = try String(contentsOf: keyFile)
|
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
keyManager = KeyManagement(deviceKey: deviceKey)
|
|
try routes(app)
|
|
|
|
// Gracefully shut down by closing potentially open socket
|
|
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .seconds(5)) {
|
|
_ = app.server.onShutdown.always { _ in
|
|
keyManager.removeDeviceConnection()
|
|
}
|
|
}
|
|
}
|