0xgio
0xgio

Reputation: 141

Pushing strapi to heroku is not generating .env file, cannot connect to postgres

I've been following the tutorial on strapi's website: https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/heroku.html#heroku-install-requirements

however, I get to step 5 of creating the postgres config, and it all gets weird. Specifically:

heroku config:set MY_HEROKU_URL=$(heroku info -s | grep web_url | cut -d= -f2)
heroku config:set APP_KEYS=$(cat .env | grep APP_KEYS | cut -d= -f2-)
heroku config:set API_TOKEN_SALT=$(cat .env | grep API_TOKEN_SALT | cut -d= -f2)
heroku config:set ADMIN_JWT_SECRET=$(cat .env | grep ADMIN_JWT_SECRET | cut -d= -f2)
heroku config:set JWT_SECRET=$(cat .env | grep -w JWT_SECRET | cut -d= -f2)

I don't understand, how are these commands supposed to set the variables when I don't even have the .env file.

How can I generate a .env file from the DATABASE_URL? The docs say that we need to include the variables such as JWT_SECRET, APP_KEYS, and SALT. Where can i get these from?

This part is supposed to parse the DATABASE_URL and generate the environment variables?

const config = parse(process.env.DATABASE_URL);

Or am i confused over here?

The project is building and pushing to heroku successfully, however running heroku open does not work.

Also, I happened to accidentally get it to work once on an new strapi project. The .env got generated on its own and the strapi server started on heroku. But now, if i delete the .env, it doesn't even generate again.

This is so frustrating, I don't know how to make it work on my actual project and not a new one.

Upvotes: 2

Views: 516

Answers (1)

patatafly
patatafly

Reputation: 164

You can make new keys randomly and add them to heroku config variables. Instead of using the part of the documentation you are using you can use this:

heroku config:set APP_KEYS=$(openssl rand -base64 32)
heroku config:set API_TOKEN_SALT=$(openssl rand -base64 32)
heroku config:set ADMIN_JWT_SECRET=$(openssl rand -base64 32)
heroku config:set JWT_SECRET=$(openssl rand -base64 32)

This should generate new keys for you. Then add MY_HEROKU_URL to them.

Upvotes: 2

Related Questions