ce1e141ca4
Delete paths.conf
39 lines
1.1 KiB
Swift
Executable File
39 lines
1.1 KiB
Swift
Executable File
import Vapor
|
|
import Foundation
|
|
|
|
|
|
private(set) var server: CapServer!
|
|
|
|
public func configure(_ app: Application) throws {
|
|
|
|
app.http.server.configuration.port = 6001
|
|
app.routes.defaultMaxBodySize = "2mb"
|
|
|
|
let configFile = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
|
.appendingPathComponent("config.json")
|
|
let config: Config
|
|
if !FileManager.default.fileExists(atPath: configFile.path) {
|
|
config = .default
|
|
let configData = try JSONEncoder().encode(config)
|
|
try configData.write(to: configFile)
|
|
print("Wrote default configuration")
|
|
} else {
|
|
let configData = try Data(contentsOf: configFile)
|
|
config = try JSONDecoder().decode(Config.self, from: configData)
|
|
}
|
|
|
|
try Log.set(logFile: config.logPath)
|
|
|
|
let publicDirectory = app.directory.publicDirectory
|
|
if config.serveFiles {
|
|
let middleware = FileMiddleware(publicDirectory: publicDirectory)
|
|
app.middleware.use(middleware)
|
|
}
|
|
|
|
server = try CapServer(in: URL(fileURLWithPath: publicDirectory))
|
|
try server.loadCapNames()
|
|
|
|
// Register routes to the router
|
|
try routes(app)
|
|
}
|