Skip to content

Conversation

@7-zete-7
Copy link

Q A
License MIT
Issue Closes #1513

Since symfony/mercure-bundle 0.4.0, support for the FrankenPHP function mercure_publish() was added.
This function is used when running project via FrankenPHP with Mercure enabled and when mercure.url isn't configured.

With this PR, I propose making mercure.url optional by default. This will allow the new function to be enabled simply when the MERCURE_URL environment variable is missing or empty.

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) January 29, 2026 09:26
@github-actions
Copy link

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1514/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1514/index.json
  2. Install the package(s) related to this recipe:

    composer req symfony/flex
    composer req 'symfony/mercure-bundle:^0.4'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

symfony/mercure-bundle

0.1 vs 0.2
diff --git a/symfony/mercure-bundle/0.1/config/packages/mercure.yaml b/symfony/mercure-bundle/0.2/config/packages/mercure.yaml
index d1947d1f..17aaa0ca 100644
--- a/symfony/mercure-bundle/0.1/config/packages/mercure.yaml
+++ b/symfony/mercure-bundle/0.2/config/packages/mercure.yaml
@@ -1,4 +1,5 @@
 mercure:
+    enable_profiler: '%kernel.debug%'
     hubs:
         default:
             url: '%env(MERCURE_PUBLISH_URL)%'
0.2 vs 0.3
diff --git a/symfony/mercure-bundle/0.2/config/packages/mercure.yaml b/symfony/mercure-bundle/0.3/config/packages/mercure.yaml
index 17aaa0ca..f2a73954 100644
--- a/symfony/mercure-bundle/0.2/config/packages/mercure.yaml
+++ b/symfony/mercure-bundle/0.3/config/packages/mercure.yaml
@@ -1,6 +1,8 @@
 mercure:
-    enable_profiler: '%kernel.debug%'
     hubs:
         default:
-            url: '%env(MERCURE_PUBLISH_URL)%'
-            jwt: '%env(MERCURE_JWT_TOKEN)%'
+            url: '%env(MERCURE_URL)%'
+            public_url: '%env(MERCURE_PUBLIC_URL)%'
+            jwt:
+                secret: '%env(MERCURE_JWT_SECRET)%'
+                publish: '*'
diff --git a/symfony/mercure-bundle/0.2/manifest.json b/symfony/mercure-bundle/0.3/manifest.json
index ba8f74df..3e21b31e 100644
--- a/symfony/mercure-bundle/0.2/manifest.json
+++ b/symfony/mercure-bundle/0.3/manifest.json
@@ -7,9 +7,47 @@
     },
     "env": {
         "#1": "See https://symfony.com/doc/current/mercure.html#configuration",
-        "MERCURE_PUBLISH_URL": "http://mercure/.well-known/mercure",
-        "#2": "The default token is signed with the secret key: !ChangeMe!",
-        "MERCURE_JWT_TOKEN": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOltdfX0.Oo0yg7y4yMa1vr_bziltxuTCqb8JVHKxp-f_FwwOim0"
+        "#2": "The URL of the Mercure hub, used by the app to publish updates (can be a local URL)",
+        "MERCURE_URL": "https://example.com/.well-known/mercure",
+        "#3": "The public URL of the Mercure hub, used by the browser to connect",
+        "MERCURE_PUBLIC_URL": "https://example.com/.well-known/mercure",
+        "#4": "The secret used to sign the JWTs",
+        "MERCURE_JWT_SECRET": "!ChangeThisMercureHubJWTSecretKey!"
+    },
+    "docker-compose": {
+        "docker-compose.yml": {
+            "services": [
+                "mercure:",
+                "  image: dunglas/mercure",
+                "  restart: unless-stopped",
+                "  environment:",
+                "    # Uncomment the following line to disable HTTPS,",
+                "    #SERVER_NAME: ':80'",
+                "    MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'",
+                "    MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'",
+                "    # Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive",
+                "    MERCURE_EXTRA_DIRECTIVES: |",
+                "      cors_origins http://127.0.0.1:8000",
+                "  # Comment the following line to disable the development mode",
+                "  command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile",
+                "  healthcheck:",
+                "    test: [\"CMD\", \"curl\", \"-f\", \"https://localhost/healthz\"]",
+                "    timeout: 5s",
+                "    retries: 5",
+                "    start_period: 60s",
+                "  volumes:",
+                "    - mercure_data:/data",
+                "    - mercure_config:/config"
+            ],
+            "volumes": ["mercure_data:", "mercure_config:"]
+        },
+        "docker-compose.override.yml": {
+            "services": [
+                "mercure:",
+                "  ports:",
+                "    - \"80\""
+            ]
+        }
     },
     "aliases": ["mercure"]
 }
0.3 vs 0.4
diff --git a/symfony/mercure-bundle/0.3/config/packages/mercure.yaml b/symfony/mercure-bundle/0.4/config/packages/mercure.yaml
index f2a73954..0f7173a3 100644
--- a/symfony/mercure-bundle/0.3/config/packages/mercure.yaml
+++ b/symfony/mercure-bundle/0.4/config/packages/mercure.yaml
@@ -1,7 +1,7 @@
 mercure:
     hubs:
         default:
-            url: '%env(MERCURE_URL)%'
+            url: '%env(default::MERCURE_URL)%'
             public_url: '%env(MERCURE_PUBLIC_URL)%'
             jwt:
                 secret: '%env(MERCURE_JWT_SECRET)%'

@7-zete-7 7-zete-7 changed the title [symfony/mercure-bundle] Make MERCURE_URL optional to allow use of FrankenPHP's built-in Mercure [symfony/mercure-bundle] Make MERCURE_URL optional to allow use of FrankenPHP's built-in Mercure Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[symfony/mercure-bundle] Allow FrankenPHP's built-in Mercure to be used by default

1 participant