-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppConfig.swift
43 lines (37 loc) · 1002 Bytes
/
AppConfig.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// AppConfig.swift
//
//
// Created by Saroar Khandoker on 20.01.2022.
//
import Vapor
struct AppConfig {
let frontendURL: String
let apiURL: String
let noReplyEmail: String
static var env: Environment = .development
static var environment: AppConfig {
let environmentNameUppercased = env.name.uppercased()
guard
let frontendURL = Environment.get("SITE_FRONTEND_URL_\(environmentNameUppercased)"),
let apiURL = Environment.get("SITE_API_URL_\(environmentNameUppercased)"),
let noReplyEmail = Environment.get("NO_REPLY_EMAIL_\(environmentNameUppercased)")
else {
fatalError("Please add app configuration to environment variables")
}
return .init(frontendURL: frontendURL, apiURL: apiURL, noReplyEmail: noReplyEmail)
}
}
extension Application {
struct AppConfigKey: StorageKey {
typealias Value = AppConfig
}
var config: AppConfig {
get {
storage[AppConfigKey.self] ?? .environment
}
set {
storage[AppConfigKey.self] = newValue
}
}
}