You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 line
1.3 KiB

  1. import NIOSSL
  2. import Fluent
  3. import FluentPostgresDriver
  4. import Vapor
  5. // configures your application
  6. public func configure(_ app: Application) async throws {
  7. app.middleware.use(CORSMiddleware())
  8. let corsConfiguration = CORSMiddleware.Configuration(
  9. allowedOrigin: .all,
  10. allowedMethods: [.GET, .POST, .PUT, .OPTIONS, .DELETE, .PATCH],
  11. allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin]
  12. )
  13. let cors = CORSMiddleware(configuration: corsConfiguration)
  14. app.middleware.use(cors, at: .beginning)
  15. app.http.server.configuration.port = 3004
  16. app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init(
  17. hostname: Environment.get("DATABASE_HOST") ?? "localhost",
  18. port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber,
  19. username: Environment.get("DATABASE_USERNAME") ?? "mcarman",
  20. password: Environment.get("DATABASE_PASSWORD") ?? "@ng31F@rm0823262",
  21. database: Environment.get("DATABASE_NAME") ?? "trainingdb",
  22. tls: .prefer(try .init(configuration: .clientDefault)))
  23. ), as: .psql)
  24. app.logger.logLevel = .debug
  25. try await doMigrations(app)
  26. // register routes
  27. try routes(app)
  28. }