HEROKU DOCKERIZED STRAPI Content Security Policy error

System Information
  • Strapi Version: 4.2.2
  • Operating System: NODE-14 alpine - Docker on Heroku
  • Database: Postgres Heroku
  • Node Version: 14.20.0
  • NPM Version: 6.14.17
  • Yarn Version: 1.22.19

I’m an old user on a new strapi 4 project.
Still getting:
Content Security Policy: The page’s settings blocked the loading of a resource at hxxp://localhost:1337/admin/project-type (“connect-src”).
Content Security Policy: The page’s settings blocked the loading of a resource at hxxp://localhost:1337/admin/init (“connect-src”).

I tried all major workaround starting from comments of last days on same error on
Strapi ⭐️ V4 with Docker 🐳 and Heroku.
Found same error references in this strapi reported issue from january… with same problem reappearing by some days, as you can check on this link:
https://github.com/strapi/strapi/issues/12129
As in the comments in the heroku tutorial of first link, seems that the issue started again recently.

Tried with npm/yarn/0.0.0.0/127.0.0.1/rebuild admin with npm after installing modules in docker/production in package.json-docker env-heroku env. Maybe some issues on cors configuration wich blocks also local??? Any other idea? I’m trying to redo all app dockerization from scratch with the Heroku/docker node/npm/yarn specific versions, maybe that fix.


So a thing to note, is that if you are hosting on heroku you can’t use localhost. I mean it’s not your machine.
So the URL should point to the URL that is used From my guide and what I wrote.

heroku config:set WEBSITE_URL=$(heroku info -a awesomestrapi -s | grep web_url | cut -d= -f2) -a awesomestrapi

This is quite important else you might get that issue.
And in the server file

module.exports = ({ env }) => ({
  url: env('WEBSITE_URL'),
  port: process.env.PORT,
});

Note here that this if for production so if you are running in development you will end up with the same problem you have now. Where it can’t connect to localhost on heroku etc and you will get CORS issues.

So check that the setup you are running is correct :slight_smile:

Yes, that was exactly what i wanted to do and how i setupped the server/admin.js following your guide (thanks, first time on strapi/docker). Too bad Heroku isn’t my personal localhost :smiley: but i’ve got similar problems with strapi also back in 2018 as CTO of the last official spinoff of the first official (and only they were saying) microsoft research center in EU. I googled a bit, and saw all that similar comments of these last days, as in your tutorial and issue link… so i lurked out asking about actual situation on official channels. I’ll try to reconfig with a plain strapi img and heroku app from scratch, maybe something from past dockerizations and integrations went and remained wrong. Not first time an img got corrupted. :slight_smile: I’ll keep you informed. Thanks again! :smiley:

Greetings. After some other tries i abandoned the dockerization, changed from container to heroku-20 and repushed, and everything started. So it’s something more heroku/docker related.