|
- import NIOSSL
- import Fluent
- import FluentPostgresDriver
- import Vapor
-
- // configures your application
- public func configure(_ app: Application) async throws {
- app.middleware.use(CORSMiddleware())
- let corsConfiguration = CORSMiddleware.Configuration(
- allowedOrigin: .all,
- allowedMethods: [.GET, .POST, .PUT, .OPTIONS, .DELETE, .PATCH],
- allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin]
- )
- let cors = CORSMiddleware(configuration: corsConfiguration)
- app.middleware.use(cors, at: .beginning)
-
- app.http.server.configuration.port = 3004
- app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init(
- hostname: Environment.get("DATABASE_HOST") ?? "localhost",
- port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber,
- username: Environment.get("DATABASE_USERNAME") ?? "mcarman",
- password: Environment.get("DATABASE_PASSWORD") ?? "@ng31F@rm0823262",
- database: Environment.get("DATABASE_NAME") ?? "trainingdb",
- tls: .prefer(try .init(configuration: .clientDefault)))
- ), as: .psql)
-
-
- app.logger.logLevel = .debug
-
- try await doMigrations(app)
-
- // register routes
- try routes(app)
- }
|