Deploy to a Server on Heroku

To Heroku - 图2info

This guide assumes the following;

  1. That you already have an Heroku account
  2. That you’ll be using the Heroku Postgres addon (since Heroku does not provide sqlite as a suitable addon)
  3. That the application is a completely new application created using the Blitz CLI.
  4. That deployments will be made with git and the Heroku CLI.

In Heroku:

  1. Create a new application in your desired region
  2. Attach the Heroku Postgres addon to your application.

In your terminal:

  1. Login to Heroku using
  1. heroku login
  1. 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.
  1. heroku git:remote --app <APP_NAME>

In your Blitz application:

  1. Configure the application to use postgres instead of the default sqlite by following the “Switch to PostgreSQL” guide.
  2. In your package.json add a start:production and an heroku-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.
  1. "scripts": {+ "start:production": "blitz start --production --port $PORT",+ "heroku-postbuild": "blitz prisma migrate deploy --preview-feature && blitz build"}
  1. Create a Procfile file inside the root of your project with the following content
  1. web: npm run start:production

Deploy using git:

With these changes committed, to deploy your application, run:

  1. git push heroku main

Once built you can open your application with the following command in your terminal

  1. 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)

  1. heroku config:set SESSION_SECRET_KEY=<SESSION_SECRET_KEY>