Detect production environment

This commit is contained in:
Christoph Hagen 2023-12-21 08:50:28 +01:00
parent a08dc4f175
commit dabc94b8b5
3 changed files with 4 additions and 14 deletions

View File

@ -1,6 +1,5 @@
{ {
"serverPort": 8000, "serverPort": 8000,
"production": false,
"mail": { "mail": {
"serverDomain": "https://example.com/schafkopf", "serverDomain": "https://example.com/schafkopf",
"emailHostname": "example.com", "emailHostname": "example.com",

View File

@ -6,13 +6,6 @@ struct Configuration {
let mail: EMail? let mail: EMail?
/**
Use a database file and reduce logging.
If this property is set to `false`, then an in-memory database is used with increased logging.
*/
let production: Bool
struct EMail { struct EMail {
/// The url to the root of the server /// The url to the root of the server

View File

@ -33,19 +33,17 @@ func configure(_ app: Application) async throws {
app.http.server.configuration.port = configuration.serverPort app.http.server.configuration.port = configuration.serverPort
// Set target environment switch app.environment {
app.environment = .production case .production:
if !configuration.production {
app.logger.logLevel = .info
log("[DEVELOPMENT] Using in-memory database") log("[DEVELOPMENT] Using in-memory database")
app.databases.use(.sqlite(.memory), as: .sqlite) app.databases.use(.sqlite(.memory), as: .sqlite)
} else { default:
app.logger.logLevel = .notice app.logger.logLevel = .notice
let dbFile = storageFolder.appendingPathComponent("db.sqlite").path let dbFile = storageFolder.appendingPathComponent("db.sqlite").path
log("[PRODUCTION] Using database at \(dbFile)") log("[PRODUCTION] Using database at \(dbFile)")
app.databases.use(.sqlite(.file(dbFile)), as: .sqlite) app.databases.use(.sqlite(.file(dbFile)), as: .sqlite)
} }
app.migrations.add(UserTableMigration()) app.migrations.add(UserTableMigration())
app.migrations.add(PasswordResetMigration()) app.migrations.add(PasswordResetMigration())