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.commands.use(RecalulateRecords(), as: "recalc") 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(CreateStatistics()) app.migrations.add(AddCodTrackerId()) // 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") encodeFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" encoder.dateEncodingStrategy = .formatted(encodeFormatter) ContentConfiguration.global.use(decoder: decoder, for: .json) // register routes try routes(app) }