|
- import NIOSSL
- import Fluent
- import FluentPostgresDriver
- import Vapor
- //import JWT
-
- extension String {
- var bytes: [UInt8] { .init(self.utf8) }
- }
-
- //extension JWKIdentifier{
- // static let `public` = JWKIdentifier(string: "public")
- // static let `private` = JWKIdentifier(string: "private")
- //}
-
- // configures your application
- public func configure(_ app: Application) async throws {
- // let privateKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key").replacingOccurrences(of: "\\n", with: "\n")
- // let privateSigner = try JWTSigner.rs256(key: .private(pem: privateKey.bytes))
- //
- // let publicKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key.pub").replacingOccurrences(of: "\\n", with: "\n")
- // let publicSigner = try JWTSigner.rs256(key: .public(pem: publicKey.bytes))
- //
- // app.jwt.signers.use(privateSigner, kid: .private)
- // app.jwt.signers.use(publicSigner, kid: .public, isDefault: true)
-
- 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)
- }
|