/
configure.swift
51 lines (44 loc) 路 1.23 KB
/
configure.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
44
45
46
47
48
49
50
51
import Vapor
public func configure(_ app: Application) throws {
app.http.server.configuration.hostname = "127.0.0.1"
switch app.environment {
case .tls:
app.http.server.configuration.port = 8443
try app.http.server.configuration.tlsConfiguration = .forServer(
certificateChain: [
.certificate(.init(
file: "/Users/tanner0101/dev/vapor/net-kit/certs/cert.pem",
format: .pem
))
],
privateKey: .file("/Users/tanner0101/dev/vapor/net-kit/certs/key.pem")
)
default:
app.http.server.configuration.port = 8080
}
// routes
try routes(app)
}
final class MemoryCache {
var storage: [String: String]
var lock: Lock
init() {
self.storage = [:]
self.lock = .init()
}
func get(_ key: String) -> String? {
self.lock.lock()
defer { self.lock.unlock() }
return self.storage[key]
}
func set(_ key: String, to value: String?) {
self.lock.lock()
defer { self.lock.unlock() }
self.storage[key] = value
}
}
extension Environment {
static var tls: Environment {
return .custom(name: "tls")
}
}