No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

54 líneas
2.1 KiB

  1. import NIOSSL
  2. import Fluent
  3. import FluentPostgresDriver
  4. import Vapor
  5. //import JWT
  6. extension String {
  7. var bytes: [UInt8] { .init(self.utf8) }
  8. }
  9. //extension JWKIdentifier{
  10. // static let `public` = JWKIdentifier(string: "public")
  11. // static let `private` = JWKIdentifier(string: "private")
  12. //}
  13. // configures your application
  14. public func configure(_ app: Application) async throws {
  15. // let privateKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key").replacingOccurrences(of: "\\n", with: "\n")
  16. // let privateSigner = try JWTSigner.rs256(key: .private(pem: privateKey.bytes))
  17. //
  18. // let publicKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key.pub").replacingOccurrences(of: "\\n", with: "\n")
  19. // let publicSigner = try JWTSigner.rs256(key: .public(pem: publicKey.bytes))
  20. //
  21. // app.jwt.signers.use(privateSigner, kid: .private)
  22. // app.jwt.signers.use(publicSigner, kid: .public, isDefault: true)
  23. app.middleware.use(CORSMiddleware())
  24. let corsConfiguration = CORSMiddleware.Configuration(
  25. allowedOrigin: .all,
  26. allowedMethods: [.GET, .POST, .PUT, .OPTIONS, .DELETE, .PATCH],
  27. allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin]
  28. )
  29. let cors = CORSMiddleware(configuration: corsConfiguration)
  30. app.middleware.use(cors, at: .beginning)
  31. app.http.server.configuration.port = 3004
  32. app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init(
  33. hostname: Environment.get("DATABASE_HOST") ?? "localhost",
  34. port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber,
  35. username: Environment.get("DATABASE_USERNAME") ?? "mcarman",
  36. password: Environment.get("DATABASE_PASSWORD") ?? "@ng31F@rm0823262",
  37. database: Environment.get("DATABASE_NAME") ?? "trainingdb",
  38. tls: .prefer(try .init(configuration: .clientDefault)))
  39. ), as: .psql)
  40. app.logger.logLevel = .debug
  41. try await doMigrations(app)
  42. // register routes
  43. try routes(app)
  44. }