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") ?? "localhost", 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(AddCasual()) // 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) let encoder = JSONEncoder() let encodeFormatter = DateFormatter() encodeFormatter.calendar = Calendar(identifier: .iso8601) encodeFormatter.locale = Locale(identifier: "en_US_POSIX") let date = Date() let tz = TimeZone.current // if tz.isDaylightSavingTime(for: date) { // encodeFormatter.timeZone = TimeZone(abbreviation: "EST") // } // else{ // encodeFormatter.timeZone = TimeZone(abbreviation: "EDT") // // } encodeFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" encoder.dateEncodingStrategy = .formatted(encodeFormatter) // override the global encoder used for the `.json` media type ContentConfiguration.global.use(decoder: decoder, for: .json) // ContentConfiguration.global.use(encoder: encoder, for: .json) // register routes try routes(app) }