configure.swift 997 B

1234567891011121314151617181920212223242526272829
  1. import NIOSSL
  2. import Fluent
  3. import FluentPostgresDriver
  4. import Leaf
  5. import Vapor
  6. // configures your application
  7. public func configure(_ app: Application) async throws {
  8. // uncomment to serve files from /Public folder
  9. // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
  10. app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init(
  11. hostname: Environment.get("DATABASE_HOST") ?? "localhost",
  12. port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber,
  13. username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
  14. password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
  15. database: Environment.get("DATABASE_NAME") ?? "vapor_database",
  16. tls: .prefer(try .init(configuration: .clientDefault)))
  17. ), as: .psql)
  18. app.migrations.add(CreateTodo())
  19. app.views.use(.leaf)
  20. // register routes
  21. try routes(app)
  22. }