Deploying a Vapor App to Heroku

976 Views

I deploy the app from the 4:15 mark until 10:10. So feel free to skip ahead to 10:10 if you don't want to watch the deployment process. I left it in the video though, just to be as thorough as possible.

Code

Sample database configuration--configure.swift

    // Configure a Postgres database
    var databases = DatabasesConfig()
    let databaseConfig: PostgreSQLDatabaseConfig
    if let url = Environment.get("DATABASE_URL") { // it will read from this URL in production
        databaseConfig = (try PostgreSQLDatabaseConfig(url: url))
    }
    else { // when environment variable not present, default to local development environment
         databaseConfig = PostgreSQLDatabaseConfig(hostname: "localhost", port: 5432, username: "yourUsername", database: "yourDatabaseName", password: nil)
    }
    let database = PostgreSQLDatabase(config: databaseConfig)
    databases.add(database: database, as: .psql)
    services.register(databases)



Enjoy this article? Consider supporting VaporForums by following us on Twitter! Get the latest Vapor articles, tutorials, and news.