Deploying A Blitz Project
Deploy to Production
- You need a production Postgres database. Here's how to set this up on Digital Ocean.
- For deploying serverless, you also need a connection pool.
- Read the Digitial Ocean docs on setting up your connection pool
- Ensure you set your "Pool Mode" to be "Session" instead of "Transaction" (because of a bug in Prisma)
- Lastly, you need your entire database connection string. If you need, read the Prisma docs on this.
- If deploying to serverless with a connection pool, make sure you get the connection string to your connection pool, not directly to the DB.
Serverless
Assuming you already have a Zeit account and the now
cli installed, you can do the following:
- Add your DB url as a secret environment variable by running
now secrets add @database-url "DATABASE_CONNECTION_STRING"
- Add a
now.json
at your project root with
{
"env": {
"DATABASE_URL": "@database-url"
},
"build": {
"env": {
"DATABASE_URL": "@database-url"
}
}
}
- Run
now
Once working and deployed to production, your app should be very stable because it’s running Next.js which is already battle tested.
Traditional, Long-Running Server
You can deploy a Blitz app like a regular Node or Express project.
blitz start --production
will start your app in production mode. Make sure you provide the DATABASE_URL
environment variable for your production database.