Deploying Crystal app to production using Heroku

This article assumes that you have Crystal and Heroku CLI installed.

Create a sample application

Create a new application using
$ crystal init app sample-app
You should see the following on your terminal
$ crystal init app sample-app
      create  sample-app/.gitignore
      create  sample-app/.editorconfig
      create  sample-app/LICENSE
      create  sample-app/
      create  sample-app/.travis.yml
      create  sample-app/shard.yml
      create  sample-app/src/
      create  sample-app/src/sample-app/
      create  sample-app/spec/
      create  sample-app/spec/
Initialized empty Git repository in /Users/yourname/Desktop/sample-app/.git/
now cd to the root of the app, $ cd sample-app  and add Kemal to shrad.yml file
name: sample-app
version: 0.1.0
  - John Doe <[email protected]>
    github: kemalcr/kemal
    branch: master
    main: src/
crystal: 0.23.1
license: MIT
and run $ crystal deps for installing dependencies.

Add a “/” route

Open file and add replace the contents with the following code
require "kemal"
get "/" do
"Hello World"
now run $ crystal src/  and go to http://localhost:3000on your browser. You should see ur app running and the message ‘Hello World’.

Deploy to Heroku

So far so good 🙂 Now let us deploy our app to Heroku. Run $ heroku create your-custom-name –buildpack You should see something like the following on your terminal.
$ heroku create your-custom-name --buildpack
Creating ⬢ your-custom-name... done
Setting buildpack to done |
You are all set. Commit and push to heroku
$ git status
$ git add -A
$ git commit -m "commit message"
$ git push heroku master
To see your app running go to . Congratulations you just deployed your crystal app to production Happy Coding]]>