diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index aec0d64..0112d72 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -98,17 +98,26 @@ private func createFileIfNeeded(at path: URL) throws { try Data().write(to: path) } +private func readConfig(at path: URL) throws -> URL { + do { + let logPath = try String(contentsOf: path) + .trimmingCharacters(in: .whitespaces) + return URL(fileURLWithPath: logPath) + } catch { + log("Failed to read configuration file at \(path.path): \(error)") + throw error + } +} + // configures your application public func configure(_ app: Application) throws { // uncomment to serve files from /Public folder // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) app.http.server.configuration.port = 9001 - let configFile = URL(fileURLWithPath: app.directory.resourcesDirectory) + let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory) .appendingPathComponent("paths.conf") - let logPath = try String(contentsOf: configFile) - .trimmingCharacters(in: .whitespaces) - let logFile = URL(fileURLWithPath: logPath) + let logFile = try readConfig(at: configPath) let listDirectory = URL(fileURLWithPath: app.directory.publicDirectory) .appendingPathComponent("lists")