Print errors on config file load

This commit is contained in:
Christoph Hagen 2022-02-10 17:16:28 +01:00
parent 896a9f79d1
commit 4baa6a6973

View File

@ -98,17 +98,26 @@ private func createFileIfNeeded(at path: URL) throws {
try Data().write(to: path) 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 // configures your application
public func configure(_ app: Application) throws { public func configure(_ app: Application) throws {
// uncomment to serve files from /Public folder // uncomment to serve files from /Public folder
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.http.server.configuration.port = 9001 app.http.server.configuration.port = 9001
let configFile = URL(fileURLWithPath: app.directory.resourcesDirectory) let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory)
.appendingPathComponent("paths.conf") .appendingPathComponent("paths.conf")
let logPath = try String(contentsOf: configFile) let logFile = try readConfig(at: configPath)
.trimmingCharacters(in: .whitespaces)
let logFile = URL(fileURLWithPath: logPath)
let listDirectory = URL(fileURLWithPath: app.directory.publicDirectory) let listDirectory = URL(fileURLWithPath: app.directory.publicDirectory)
.appendingPathComponent("lists") .appendingPathComponent("lists")