'Errors deploying Strapi in Digital Ocean Droplet: because it violates the following Content Security Policy directive: "connect-src 'self' https:

I am new to Digital Ocean and deploying strapi for production.

I have managed to create a new Digital Ocean droplet running Ubuntu 20 and I have installed node js in it. I also installed nginx although I doubt if I'm using it correctly at this point.

In any case I managed to fix all the errors that are related to the strapi application and I have managed to get strapi to run on port 1337 of the droplet. The default port 80 is being used by the nginx server. http://137.184.181.149:80 and strapi is running on port 1337

http://137.184.181.149:1337/admin

You can see the actual error if you click on the above link and check the console logs.

Console logs display:

main.25315363.js:7519 Refused to connect to 'http://localhost:1337/admin/project-type' because it violates the following Content Security Policy directive: "connect-src 'self' https:".

(anonymous) @ main.25315363.js:7519
M.exports @ main.25315363.js:7519
M.exports @ main.25315363.js:7519
Promise.then (async)
r.request @ main.25315363.js:7519
r.<computed> @ main.25315363.js:7519
(anonymous) @ main.25315363.js:7519
(anonymous) @ main.25315363.js:7776
(anonymous) @ main.25315363.js:7776
Sc @ main.25315363.js:7776
(anonymous) @ main.25315363.js:7776
76442 @ main.25315363.js:7776
s @ runtime~main.1ecd9f7d.js:1
h @ main.25315363.js:7909
(anonymous) @ main.25315363.js:7909
r @ runtime~main.1ecd9f7d.js:2
(anonymous) @ main.25315363.js:1
main.25315363.js:7776 Error: Network Error
    at M.exports (main.25315363.js:7519:7821)
    at XMLHttpRequest.E.onerror (main.25315363.js:7519:2814)
(anonymous) @ main.25315363.js:7776
tn @ main.25315363.js:7776
Promise.then (async)
Yt @ main.25315363.js:7776
(anonymous) @ main.25315363.js:7776
Sc @ main.25315363.js:7776
(anonymous) @ main.25315363.js:7776
76442 @ main.25315363.js:7776
s @ runtime~main.1ecd9f7d.js:1
h @ main.25315363.js:7909
(anonymous) @ main.25315363.js:7909
r @ runtime~main.1ecd9f7d.js:2
(anonymous) @ main.25315363.js:1
main.25315363.js:7502 Refused to connect to 'http://localhost:1337/admin/init' because it violates the following Content Security Policy directive: "connect-src 'self' https:".

$.default @ main.25315363.js:7502
(anonymous) @ 6706.b0b5124d.chunk.js:16
(anonymous) @ 6706.b0b5124d.chunk.js:16
Jt @ 6706.b0b5124d.chunk.js:16
(anonymous) @ 6706.b0b5124d.chunk.js:16
(anonymous) @ 6706.b0b5124d.chunk.js:16
Uc @ main.25315363.js:7589
h.unstable_runWithPriority @ main.25315363.js:7621
Vi @ main.25315363.js:7585
fu @ main.25315363.js:7589
(anonymous) @ main.25315363.js:7589
k @ main.25315363.js:7621
x.port1.onmessage @ main.25315363.js:7621
main.25315363.js:7502 Refused to connect to 'http://localhost:1337/admin/init' because it violates the document's Content Security Policy.

What am I doing wrong? How to fix this? I would like to access my strapi app via the IP address and perhaps even through a domain I assign....

Currently the strapi app is on the home folder /~

Should I be putting the strapi app inside one of the folders of nginx???



Solution 1:[1]

Did you try to delete the strapi .cache folder ?

You can also check for the host in the strapi config file, mine is here: config/server.js

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1