import Vapor import Foundation import Clairvoyant public func configure(_ app: Application) throws { let resourceDirectory = URL(fileURLWithPath: app.directory.resourcesDirectory) let publicDirectory = app.directory.publicDirectory let config = Config(loadFrom: resourceDirectory) let authenticator = Authenticator(writers: config.writers) let monitor = MetricObserver( logFolder: config.logURL, accessManager: authenticator, logMetricId: "caps.log") // All new metrics are automatically registered with the standard observer MetricObserver.standard = monitor let status = Metric("caps.status", name: "Status", description: "The general status of the service") status.update(.initializing) let server = CapServer(in: URL(fileURLWithPath: publicDirectory)) 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) } // Register routes to the router server.registerRoutes(with: app, authenticator: authenticator) // Initialize the server data do { try server.loadData() status.update(.nominal) } catch { status.update(.initializationFailure) } } func log(_ message: String) { MetricObserver.standard?.log(message) print(message) }