diff --git a/Resources/example_config.json b/Resources/example_config.json index 2a4e0f4..2270188 100644 --- a/Resources/example_config.json +++ b/Resources/example_config.json @@ -3,6 +3,7 @@ "maxBodySize" : "2mb", "logPath": "\/var\/log\/caps/metrics", "serveFiles": true, + "dataDirectory" : "/ch/data/caps", "writers" : [ "auth_key_1" ] diff --git a/Sources/App/Config.swift b/Sources/App/Config.swift index cd8acd6..03e9284 100644 --- a/Sources/App/Config.swift +++ b/Sources/App/Config.swift @@ -20,6 +20,15 @@ struct Config: Codable { /// Authentication tokens for remotes allowed to write let writers: [String] + let dataDirectory: String? + + func customDataDirectory(or publicDirectory: String) -> URL { + guard let dataDirectory else { + return URL(fileURLWithPath: publicDirectory) + } + return URL(fileURLWithPath: dataDirectory) + } + func logURL(possiblyRelativeTo resourcesDirectory: URL) -> URL { guard let logPath else { return resourcesDirectory.appendingPathComponent("logs") diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 0c0dc25..1f74e4d 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -31,7 +31,8 @@ func configure(_ app: Application) async throws { app.http.server.configuration.port = config.port app.routes.defaultMaxBodySize = .init(stringLiteral: config.maxBodySize) - server = CapServer(in: URL(fileURLWithPath: publicDirectory)) + let dataDirectory = config.customDataDirectory(or: publicDirectory) + server = CapServer(in: dataDirectory) provider = .init(observer: monitor, accessManager: config.writers) provider.asyncScheduler = asyncScheduler