naskio / docker-strapi

Docker image for strapi v4 (latest version)
https://hub.docker.com/r/naskio/strapi
MIT License
142 stars 49 forks source link

Refused to connect to 'http://localhost:1337/admin/project-type' to Strapi in k8s #20

Closed ilyinon closed 1 year ago

ilyinon commented 1 year ago

Hi!

I would like to ask you help to solve the issue when you deploy the image ( the latest one) to kubernetes. It is up and running and it is available thru ingress, yet /admin doesn't work properly and you can see the following errors in the console.

admin:1 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-bG7bn3LjdHcCH2ZHSejHnSWxixr/KhYaBobyVrfB8g4='), or a nonce ('nonce-...') is required to enable inline execution.

main.1f8cc299.js:2856 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.1f8cc299.js:2856
xhr @ main.1f8cc299.js:2856
$e @ main.1f8cc299.js:2856
Promise.then (async)
request @ main.1f8cc299.js:2856
Fn.<computed> @ main.1f8cc299.js:2856
(anonymous) @ main.1f8cc299.js:2854
get @ main.1f8cc299.js:955
(anonymous) @ main.1f8cc299.js:452
32741 @ main.1f8cc299.js:452
e @ runtime~main.80a43c16.js:1
x @ main.1f8cc299.js:2856
(anonymous) @ main.1f8cc299.js:2856
i @ runtime~main.80a43c16.js:2
(anonymous) @ main.1f8cc299.js:1
main.1f8cc299.js:452 Qt {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
(anonymous) @ main.1f8cc299.js:452
await in (anonymous) (async)
32741 @ main.1f8cc299.js:452
e @ runtime~main.80a43c16.js:1
x @ main.1f8cc299.js:2856
(anonymous) @ main.1f8cc299.js:2856
i @ runtime~main.80a43c16.js:2
(anonymous) @ main.1f8cc299.js:1
main.1f8cc299.js:2856 Refused to connect to 'http://localhost:1337/admin/init' because it violates the following Content Security Policy directive: "connect-src 'self' https:".

strapi has the following output

Actions available

One more thing...
Create your first administrator 💻 by going to the administration panel at:

┌───────────────────────────┐
│ http://0.0.0.0:1337/admin │
└───────────────────────────┘

[2023-08-11 12:44:23.767] http: GET /admin (21 ms) 200
[2023-08-11 12:44:23.842] http: GET /admin/runtime~main.80a43c16.js (9 ms) 200
[2023-08-11 12:44:23.843] http: GET /admin/main.1f8cc299.js (3 ms) 200
[2023-08-11 12:44:24.786] http: GET /favicon.ico (1 ms) 200
[2023-08-11 12:44:30.144] http: GET /admin (2 ms) 200
[2023-08-11 12:44:30.196] http: GET /admin/runtime~main.80a43c16.js (1 ms) 200
[2023-08-11 12:44:30.200] http: GET /admin/main.1f8cc299.js (1 ms) 200
[2023-08-11 12:44:31.862] http: GET /favicon.ico (0 ms) 200
[2023-08-11 12:45:41.648] http: GET /admin (2 ms) 200
[2023-08-11 12:45:41.737] http: GET /admin/main.1f8cc299.js (3 ms) 200
[2023-08-11 12:45:41.738] http: GET /admin/runtime~main.80a43c16.js (2 ms) 200
[2023-08-11 12:45:42.688] http: GET /favicon.ico (0 ms) 200
[2023-08-11 12:47:10.666] http: GET /admin (2 ms) 200
[2023-08-11 12:47:10.737] http: GET /admin/runtime~main.80a43c16.js (2 ms) 200
[2023-08-11 12:47:10.741] http: GET /admin/main.1f8cc299.js (1 ms) 200
[2023-08-11 12:47:12.557] http: GET /favicon.ico (0 ms) 200

and I pass the ADMIN_URL and PUBLIC_URL ADMIN_URL=https://strapi.domain/admin PUBLIC_URL=https://strapi.domain

Elu43 commented 1 year ago

Hi, I had similar problem (it was trying to reach localhost). I removed all env variables from my docker compose, I manually edited ./config/server.js to add :

module.exports = ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), url: env('PUBLIC_URL', 'https://youraddresshere'),

Then you have to docker exec inside the container, run "strapi build", restart the container.

ilyinon commented 1 year ago

@Elu43 thank you a lot! It works.

I've added updated server.js to the dockerfile, steps with copying server.js and running "strapi build" to entrypoint.sh and after these steps it works like a charm!

Dockerfile

..
COPY docker-entrypoint.sh /usr/local/bin/
COPY server.js /srv/server.js
..

docker-entrypoint.sh

..
     $EXTRA_ARGS
    cp -f /srv/server.js /srv/app/config/server.js
    strapi build

  elif [ ! -d "node_modules" ] || [ ! "$(ls -qAL node_modules 2>/dev/null)" ]; then
..