Root domain resolves, www subdomain causes 520 error

Regarding Cloudflare 520 error, may I suggest you to try looking into below articles to troubleshoot the issue:

https://support.cloudflare.com/hc/en-us/articles/115003011431-Troubleshooting-Cloudflare-5XX-errors#520error

May I ask was the DNSSEC enabled for your domain before you changed your nameservers to Cloudflare?

Regarding Heroku and HTTPS, may I also ask did they provided you with an SSL certificate for your domain (covering both www and non-www) and was your Website working over HTTPS before moving to Cloudflare?

Kindly, check and post back here what SSL option have you got selected under the SSL/TLS tab at Cloudflare dashboard for your domain? (Flexible, Full, Full Strict …)

Here is a way to re-check if you correctly setup the SSL for your domain with Cloudflare:

If any other issues appear, follow the needed steps for troubleshooting from article below:

Regarding available SSL options at Cloudflare dashboard, check here:

In case you do not have an SSL certificate, you can use Cloudflare SSL, if so, kindly make sure you follow the instructions as follows on the below article to setup an SSL certificate using Cloudflare CA Origin Certificate:

Last but not least, kindly have a look here for more information regarding correct SSL settings:

Few tips to check out for:

https://www.drivereasy.com/knowledge/fix-err-empty-response-on-google-chrome/

https://www.troubleshootingcentral.com/how-to-fix-err-empty-response-in-chrome/