import Fluent import FluentPostgresDriver import Vapor // configures your application public func configure(_ app: Application) throws { // uncomment to serve files from /Public folder // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory)) // using custom configuration app.middleware.use(CORSMiddleware(configuration: .init( allowedOrigin: .all, allowedMethods: [.GET, .POST, .PUT, .OPTIONS, .DELETE, .PATCH], allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith] ))) app.http.server.configuration.hostname = "0.0.0.0" app.http.server.configuration.port = 8080 app.databases.use(.postgres( hostname: Environment.get("DATABASE_HOST") ?? "api.sledsoft.com", username: Environment.get("DATABASE_USERNAME") ?? "cod", password: Environment.get("DATABASE_PASSWORD") ?? "pw4cod", database: Environment.get("DATABASE_NAME") ?? "cod_db" ), as: .psql) //app.migrations.add(CreateMatch()) app.migrations.add(AddCODGame2()) // create a new JSON encoder that uses unix-timestamp dates let decoder = JSONDecoder() let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) formatter.locale = Locale(identifier: "en_US_POSIX") formatter.timeZone = TimeZone(secondsFromGMT: 0) formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" decoder.dateDecodingStrategy = .formatted(formatter) // override the global encoder used for the `.json` media type ContentConfiguration.global.use(decoder: decoder, for: .json) // register routes try routes(app) }