Schafkopf-Server/Sources/App/configure.swift

39 lines
1.2 KiB
Swift
Raw Normal View History

2021-11-25 19:15:38 +01:00
import Vapor
import Fluent
2021-11-25 19:15:38 +01:00
var server: SQLiteDatabase!
2021-11-27 11:59:13 +01:00
2021-11-25 19:15:38 +01:00
// configures your application
public func configure(_ app: Application) throws {
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
2021-12-09 14:47:18 +01:00
2021-12-23 09:38:31 +01:00
app.http.server.configuration.port = 6002
2021-12-09 14:47:18 +01:00
// Set target environment
2021-12-18 15:08:43 +01:00
app.environment = .production
if app.environment == .development {
app.logger.logLevel = .info
print("[DEVELOPMENT] Using in-memory database")
app.databases.use(.sqlite(.memory), as: .sqlite)
} else {
app.logger.logLevel = .notice
let dbFile = storageFolder.appendingPathComponent("db.sqlite").path
print("[PRODUCTION] Using database at \(dbFile)")
app.databases.use(.sqlite(.file(dbFile)), as: .sqlite)
}
app.migrations.add(UserTableMigration())
try app.autoMigrate().wait()
2021-12-09 14:47:18 +01:00
2021-11-27 11:59:13 +01:00
// serve files from /Public folder
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
2021-11-25 19:15:38 +01:00
let db = app.databases.database(.sqlite, logger: .init(label: "Init"), on: app.databases.eventLoopGroup.next())!
server = try SQLiteDatabase(db: db)
2021-11-25 19:15:38 +01:00
// register routes
try routes(app)
}