Skip to content
/ koolaid Public

Simple Kotlin + DropWizard + Heroku cloud demo

Notifications You must be signed in to change notification settings

cbeust/koolaid

Repository files navigation

Kotlin + DropWizard + Postgres + Heroku demo application

This is a simple application showing how to deploy a database-backed web application written in Kotlin on Heroku. Click on the screenshot below to run the app (it might take 10-20 seconds if the app was put to sleep by Heroku):

Landing page

Stack used

  • Kotlin
  • DropWizard
  • PostgreSQL
  • Guice
  • vue.js

Building and running

./gradlew run

Then open http://localhost. You should see a page telling you how many times it's been accessed (this counter is saved in PostgreSQL).

This app is also currently running on Heroku here.

Deploying on Heroku

You can deploy this application on your own Heroku instance by pressing this button:

Deploy

Development

This application will automatically detect its environment and deploy correctly:

  • If run locally, it will use an in-memory persistence for the counter.
  • If deployed on Heroku, it will use a Postgres database.

If you want to develop locally on your own Postgres instance, copy the file local.properties.sample to local.properties and adjust the following values in order to connect to your local PostgreSQL instance:

# local.properties

# Valid: postgres | inMemory
DATABASE=postgres

DATABASE_USER=foo
DATABASE_PASSWORD=bar

Access to the local.properties file is managed by LocalProperties.

Architecture

Persistence is abstracted by the ViewsDao interface, which is implemented by both ViewsDaoPostgres and ViewsDaoInMemory.

Which implementation to use is decided by DemoModule based on the environment: if running on Heroku or locally with the Postgres coordinates defined, use Postgres, otherwise use the in-memory DAO. The correct DAO is then injected in the ViewService by Guice.

Whenever the landing page is refreshed, the vue.js app defined in demo.js makes an HTTP call to /api/v0/views which returns the number of views, increments that counter, and saves it into the ViewsDao object.

About

Simple Kotlin + DropWizard + Heroku cloud demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published