2020-05-17 20:01:30 +02:00
|
|
|
import Vapor
|
|
|
|
|
2021-11-08 21:58:55 +01:00
|
|
|
|
|
|
|
private(set) var server: CapServer!
|
|
|
|
|
2020-09-20 11:36:35 +02:00
|
|
|
// configures your application
|
|
|
|
public func configure(_ app: Application) throws {
|
|
|
|
// uncomment to serve files from /Public folder
|
|
|
|
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
|
2020-09-20 12:36:10 +02:00
|
|
|
|
|
|
|
app.http.server.configuration.port = 6001
|
2021-01-09 17:30:00 +01:00
|
|
|
app.routes.defaultMaxBodySize = "2mb"
|
2020-09-20 12:36:10 +02:00
|
|
|
|
2021-11-08 21:58:55 +01:00
|
|
|
let configFile = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
|
|
|
.appendingPathComponent("paths.conf")
|
|
|
|
let configData = try String(contentsOf: configFile)
|
|
|
|
.components(separatedBy: "\n")
|
|
|
|
.map { $0.trimmingCharacters(in: .whitespaces) }
|
|
|
|
.filter { !$0.isEmpty }
|
2022-02-24 11:40:21 +01:00
|
|
|
guard configData.count >= 2 else {
|
2022-02-24 12:31:00 +01:00
|
|
|
print("Invalid configuration file: \(configData.count) lines")
|
2021-11-08 21:58:55 +01:00
|
|
|
throw CapError.invalidConfiguration
|
|
|
|
}
|
|
|
|
let logFile = URL(fileURLWithPath: configData[0])
|
|
|
|
let publicDirectory = URL(fileURLWithPath: configData[1])
|
|
|
|
|
|
|
|
try Log.set(logFile: logFile.path)
|
|
|
|
|
|
|
|
server = try CapServer(in: publicDirectory)
|
|
|
|
try server.loadCapNames()
|
|
|
|
|
2020-05-17 20:01:30 +02:00
|
|
|
// Register routes to the router
|
2020-09-20 11:36:35 +02:00
|
|
|
try routes(app)
|
2020-05-17 20:01:30 +02:00
|
|
|
// Configure the rest of your application here
|
|
|
|
}
|