Deploy to a Server on Heroku
info
This guide assumes the following;
- That you already have an Heroku account
- That you’ll be using the Heroku Postgres addon (since Heroku does not provide sqlite as a suitable addon)
- That the application is a completely new application created using the Blitz CLI.
- That deployments will be made with git and the Heroku CLI.
In Heroku:
- Create a new application in your desired region
- Attach the Heroku Postgres addon to your application.
In your terminal:
- Login to Heroku using
heroku login
- Add your Heroku app as a git remote with the following command replacing
<APP_NAME>
with the name you provided or that was given to you when creating the Heroku app.
heroku git:remote --app <APP_NAME>
In your Blitz application:
- Configure the application to use postgres instead of the default sqlite by following the “Switch to PostgreSQL” guide.
- In your package.json add a
start:production
and anheroku-postbuild
command. This command is what Heroku will run when building your application for deploy. So we’ll use it to migrate any database changes and to build a production bundle of your app.
"scripts": {+ "start:production": "blitz start --production --port $PORT",+ "heroku-postbuild": "blitz prisma migrate deploy --preview-feature && blitz build"}
- Create a
Procfile
file inside the root of your project with the following content
web: npm run start:production
Deploy using git:
With these changes committed, to deploy your application, run:
git push heroku main
Once built you can open your application with the following command in your terminal
heroku open
Note: While the application should now be working you will not be able to use authentication until you provide Heroku with a
SESSION_SECRET_KEY
envivonment variable. You can do this with the following command replacing <MY_SECRET>
with your secret (at least 32 characters long)
heroku config:set SESSION_SECRET_KEY=<SESSION_SECRET_KEY>