2022-01-23 20:49:06 +01:00
|
|
|
import Vapor
|
|
|
|
|
2022-01-24 17:17:06 +01:00
|
|
|
var keyManager: KeyManagement!
|
|
|
|
|
2022-01-23 20:49:06 +01:00
|
|
|
// configures your application
|
|
|
|
public func configure(_ app: Application) throws {
|
2022-01-25 18:22:33 +01:00
|
|
|
app.http.server.configuration.port = 6003
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
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)
|
2022-01-23 20:49:06 +01:00
|
|
|
try routes(app)
|
2022-01-24 17:17:06 +01:00
|
|
|
|
|
|
|
// Gracefully shut down by closing potentially open socket
|
|
|
|
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .seconds(5)) {
|
|
|
|
_ = app.server.onShutdown.always { _ in
|
|
|
|
keyManager.removeDeviceConnection()
|
|
|
|
}
|
|
|
|
}
|
2022-01-23 20:49:06 +01:00
|
|
|
}
|