dunglas / mercure

🪽 An open, easy, fast, reliable and battery-efficient solution for real-time communications
https://mercure.rocks
GNU Affero General Public License v3.0
3.83k stars 278 forks source link

CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource #911

Open vitamin-code opened 4 weeks ago

vitamin-code commented 4 weeks ago

Hello,

I finally installed the mercure hub on a virtual machine. My publish is working but when I'm trying to subscribe, then I get the CORS error. I'm running the mercure hub docker image inside the ubuntu VM and within that VM, I have nginx that listens to that port 8080.

Here's my nginx

image

Here's my docker run command:

docker run -d -e SERVER_NAME=':80' 
-e MERCURE_PUBLISHER_JWT_KEY='MY_MERCURE_JWT_KEY' 
-e MERCURE_SUBSCRIBER_JWT_KEY='MY_MERCURE_JWT_KEY' 
-e MERCURE_EXTRA_DIRECTIVES="cors_origins https://localhost:8000" 
-p 8080:80 dunglus/mercure

Still, I get the CORS error on my local

dunglas commented 4 weeks ago

For Caddy to read the host forwarded by NGINX, you have to the trusted_proxies global option: https://caddyserver.com/docs/caddyfile/options#trusted-proxies

Could you check if it fixes your issue?

vitamin-code commented 2 weeks ago

Hi @dunglas , I don't know where to find the Caddy file since I'm running inside the virtual machine a docker to run the mercure container