import Vapor import Foundation import Clairvoyant private(set) var server: CapServer! private(set) var monitor: PropertyManager! public func configure(_ app: Application) throws { let resourceDirectory = URL(fileURLWithPath: app.directory.resourcesDirectory) let publicDirectory = app.directory.publicDirectory let config = Config(loadFrom: resourceDirectory) server = CapServer(in: URL(fileURLWithPath: publicDirectory), writers: config.writers) monitor = .init(logFolder: config.logURL, serverOwner: server) monitor.update(status: .initializing) server.registerProperties(with: monitor) monitor.registerRoutes(app) app.http.server.configuration.port = config.port app.routes.defaultMaxBodySize = .init(stringLiteral: config.maxBodySize) if config.serveFiles { let middleware = FileMiddleware(publicDirectory: publicDirectory) app.middleware.use(middleware) } do { try server.loadData() } catch { monitor.update(status: .initializationFailure) return } // Register routes to the router routes(app) monitor.update(status: .nominal) } func log(_ message: String) { monitor.log(message) print(message) }