main.swift 814 B

12345678910111213141516171819202122232425262728293031
  1. import Hummingbird
  2. import HummingbirdFoundation
  3. import PostgresKit
  4. extension Int {
  5. func bound(_ minValue: Int, _ maxValue: Int) -> Int {
  6. return Swift.min(maxValue, Swift.max(minValue, self))
  7. }
  8. }
  9. func runApp() throws {
  10. let env = HBEnvironment()
  11. let serverHostName = env.get("SERVER_HOSTNAME") ?? "127.0.0.1"
  12. let serverPort = env.get("SERVER_PORT", as: Int.self) ?? 8080
  13. let configuration = HBApplication.Configuration(
  14. address: .hostname(serverHostName, port: serverPort),
  15. serverName: "Hummingbird"
  16. )
  17. let app = HBApplication(configuration: configuration)
  18. app.encoder = JSONEncoder()
  19. app.initConnectionPool()
  20. WorldController().add(to: app.router)
  21. FortunesController().add(to: app.router)
  22. try app.start()
  23. app.wait()
  24. }
  25. try runApp()