Skip to content

[mercure] compatibility with v0.8 #12603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/mercure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Usage
The following example shows the component in action::

// change these values accordingly to your hub installation
define('HUB_URL', 'https://demo.mercure.rocks/hub');
define('HUB_URL', 'https://demo.mercure.rocks/.well-known/mercure');
define('JWT', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.LRLvirgONK13JgacQ_VbcjySbVhkSmHy3IznH3tA9PM');

use Symfony\Component\Mercure\Jwt\StaticJwtProvider;
Expand Down
20 changes: 10 additions & 10 deletions mercure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Run the following command to start it:

.. code-block:: terminal

$ JWT_KEY='aVerySecretKey' ADDR='localhost:3000' ALLOW_ANONYMOUS=1 CORS_ALLOWED_ORIGINS=* ./mercure
$ ./mercure --jwt-key='aVerySecretKey' --addr='localhost:3000' --allow-anonymous --cors-allowed-origins='*'

.. note::

Expand All @@ -94,7 +94,7 @@ The preferred way to configure the MercureBundle is using
Set the URL of your hub as the value of the ``MERCURE_PUBLISH_URL`` env var.
The ``.env`` file of your project has been updated by the Flex recipe to
provide example values.
Set it to the URL of the Mercure Hub (``http://localhost:3000/hub`` by default).
Set it to the URL of the Mercure Hub (``http://localhost:3000/.well-known/mercure`` by default).

In addition, the Symfony application must bear a `JSON Web Token`_ (JWT)
to the Mercure Hub to be authorized to publish updates.
Expand Down Expand Up @@ -189,7 +189,7 @@ Subscribing to updates in JavaScript is straightforward:

.. code-block:: javascript

const eventSource = new EventSource('http://localhost:3000/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
const eventSource = new EventSource('http://localhost:3000/.well-known/mercure?topic=' + encodeURIComponent('http://example.com/books/1'));
eventSource.onmessage = event => {
// Will be called every time an update is published by the server
console.log(JSON.parse(event.data));
Expand All @@ -201,7 +201,7 @@ and to use URI Templates as patterns:
.. code-block:: javascript

// URL is a built-in JavaScript class to manipulate URLs
const url = new URL('http://localhost:3000/hub');
const url = new URL('http://localhost:3000/.well-known/mercure');
url.searchParams.append('topic', 'http://example.com/books/1');
// Subscribe to updates of several Book resources
url.searchParams.append('topic', 'http://example.com/books/2');
Expand Down Expand Up @@ -295,7 +295,7 @@ by using the ``AbstractController::addLink`` helper method::
// This parameter is automatically created by the MercureBundle
$hubUrl = $this->getParameter('mercure.default_hub');

// Link: <http://localhost:3000/hub>; rel="mercure"
// Link: <http://localhost:3000/.well-known/mercure>; rel="mercure"
$this->addLink($request, new Link('mercure', $hubUrl));

return $this->json([
Expand All @@ -311,7 +311,7 @@ and to subscribe to it:
.. code-block:: javascript

// Fetch the original resource served by the Symfony web API
fetch('/books/1') // Has Link: <http://localhost:3000/hub>; rel="mercure"
fetch('/books/1') // Has Link: <http://localhost:3000/.well-known/mercure>; rel="mercure"
.then(response => {
// Extract the hub URL from the Link header
const hubUrl = response.headers.get('Link').match(/<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/)[1];
Expand Down Expand Up @@ -420,7 +420,7 @@ And here is the controller::
$response = $this->json(['@id' => '/demo/books/1', 'availability' => 'https://schema.org/InStock']);
$response->headers->set(
'set-cookie',
sprintf('mercureAuthorization=%s; path=/hub; secure; httponly; SameSite=strict', $token)
sprintf('mercureAuthorization=%s; path=/.well-known/mercure; secure; httponly; SameSite=strict', $token)
);

return $response;
Expand Down Expand Up @@ -460,7 +460,7 @@ Then, reference this service in the bundle configuration:
mercure:
hubs:
default:
url: https://mercure-hub.example.com/hub
url: https://mercure-hub.example.com/.well-known/mercure
jwt_provider: App\Mercure\MyJwtProvider

.. code-block:: xml
Expand All @@ -470,7 +470,7 @@ Then, reference this service in the bundle configuration:
<config>
<hub
name="default"
url="https://mercure-hub.example.com/hub"
url="https://mercure-hub.example.com/.well-known/mercure"
jwt-provider="App\Mercure\MyJwtProvider"
/>
</config>
Expand All @@ -483,7 +483,7 @@ Then, reference this service in the bundle configuration:
$container->loadFromExtension('mercure', [
'hubs' => [
'default' => [
'url' => 'https://mercure-hub.example.com/hub',
'url' => 'https://mercure-hub.example.com/.well-known/mercure',
'jwt_provider' => MyJwtProvider::class,
],
],
Expand Down