mehlichmeyer
mehlichmeyer

Reputation: 154

Request with Symfony HttpClient returns code 0, when the same request with postman works fine

I have a weird problem where a request I make (to my mercure hub) with postman works fine, however the Publisher class (from the Symfony mercure bundle), which uses the Symfony HttpClient will yield in a response code 0. According to my research that means that the URL can't be found, or no Response was returned?

I first thought it might have to do something with the Publisher class itself, which is why opened this Issue on Github, but after some playing around I thought that maybe there is a communication error with my containers? I tried giving my mercure container "networks: internal", which some other containers use aswell, but that didn't help either.

Any ideas are greatly appreciated..

/e: my docker-compose:

version: "3"

services:
  traefik:
    image: traefik:v1.7
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./.docker/traefik/traefik.toml:/etc/traefik/traefik.toml
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.docker.network=proxy
      - traefik.frontend.rule=Host:traefik.heracles.local
      - traefik.port=8080

  nginx:
    image: nginx:1.17-alpine
    volumes:
      - ./Source:/var/www
      - ./.docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
    links:
      - php
    networks:
      - internal
      - proxy
    labels:
      - traefik.docker.network=proxy
      - traefik.enable=true
      - traefik.basic.frontend.rule=Host:heracles.local
      - traefik.basic.port=80

  php:
    build:
      args:
        USER_ID: ${USER_ID}
      context: ./.docker/php
    volumes:
      - ./Source:/var/www
      - ./.docker/php/conf/cli.ini:/etc/php/7.4/cli/conf.d/zz-symfony.ini
      - ./.docker/php/conf/fpm.ini:/etc/php/7.4/fpm/conf.d/zz-symfony.ini
      - ./.docker/php/conf/xdebug.ini:/etc/php/7.4/fpm/conf.d/zz-xdebug.ini
      - ./.docker/php/conf/opcache.ini:/etc/php/7.4/fpm/conf.d/zz-opcache.ini
      - ./.docker/php/conf/pool.conf:/etc/php/7.4/fpm/pool.d/www.conf
    networks:
      - internal
    labels:
      - traefik.enable=false

  db:
    image: mysql:5.7
    env_file:
      - .env
    volumes:
      - db_data:/var/lib/mysql
      - ./.docker/mysql/conf.d:/etc/mysql/conf.d
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --skip-character-set-client-handshake
    networks:
      - internal
    labels:
      - traefik.enable=false
    restart: always

  adminer:
    image: adminer
    networks:
      - internal
      - proxy
    labels:
      - traefik.docker.network=proxy
      - traefik.enable=true
      - traefik.basic.frontend.rule=Host:db.heracles.local
      - traefik.basic.port=8080

  blackfire:
    image: blackfire/blackfire
    networks:
      - internal
    labels:
      - traefik.enable=false

  mailhog:
    image: mailhog/mailhog
    networks:
      - internal
      - proxy
    labels:
      - traefik.docker.network=proxy
      - traefik.enable=true
      - traefik.basic.frontend.rule=Host:mail.heracles.local
      - traefik.basic.port=8025

  mercure:
    image: dunglas/mercure
    environment:
      - ALLOW_ANONYMOUS=1
      - CORS_ALLOWED_ORIGINS=*
      - JWT_KEY=ASD
      - PUBLISH_ALLOWED_ORIGINS=http://heracles.local
      - ADDR=:3000
    ports:
      - 3000:3000

networks:
  internal:
  proxy:
    external: true

volumes:
  db_data:

Upvotes: 1

Views: 2792

Answers (2)

mehlichmeyer
mehlichmeyer

Reputation: 154

Alright guys it's working now. In fact the correct url is MERCURE_PUBLISH_URL=http://mercure:3000/.well-known/mercure So if you're using Docker Containers make sure to pass the correct host + the port and give your mercure containers the network of your other containers (internal in my case).

Upvotes: 0

Chloé
Chloé

Reputation: 354

In reference to your comment, your MERCURE_PUBLISH_URL .env variable must indeed refer to your Mercure container, but there's no need for the port indication. If the name of your Mercure container is "mercure", the environment variable should be set like so :

MERCURE_PUBLISH_URL=http://mercure/.well-known/mercure

(Replace http by https if your connection is secured)

Upvotes: 1

Related Questions