Skip to content

Commit 7f3b6a0

Browse files
authored
feat: extract Mercure hub from response headers (#1480)
1 parent d0ba811 commit 7f3b6a0

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

admin/components.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ const App = () => (
219219
entrypoint={entrypoint}
220220
dataProvider={dataProvider}
221221
authProvider={authProvider}
222-
mercure={true}
223222
>
224223
<ResourceGuesser name="books" />
225224
{ /* ... */ }

admin/customizing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ To cherry-pick the resources to make available through the admin, pass a list of
1717
import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";
1818

1919
export default () => (
20-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true}>
20+
<HydraAdmin entrypoint="https://demo.api-platform.com">
2121
<ResourceGuesser name="books" />
2222
<ResourceGuesser name="reviews" />
2323

@@ -52,7 +52,7 @@ const ReviewsList = props => (
5252
);
5353

5454
export default () => (
55-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true}>
55+
<HydraAdmin entrypoint="https://demo.api-platform.com">
5656
<ResourceGuesser name="reviews" list={ReviewsList} />
5757
{/* ... */}
5858
</HydraAdmin>
@@ -90,7 +90,7 @@ const ReviewsShow = props => (
9090
);
9191

9292
export default () => (
93-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true}>
93+
<HydraAdmin entrypoint="https://demo.api-platform.com">
9494
<ResourceGuesser name="reviews" show={ReviewsShow} />
9595
{/* ... */}
9696
</HydraAdmin>
@@ -126,7 +126,7 @@ const ReviewsCreate = props => (
126126
);
127127

128128
export default () => (
129-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true}>
129+
<HydraAdmin entrypoint="https://demo.api-platform.com">
130130
<ResourceGuesser name="reviews" create={ReviewsCreate} />
131131
{/* ... */}
132132
</HydraAdmin>
@@ -164,7 +164,7 @@ const ReviewsEdit = props => (
164164
);
165165

166166
export default () => (
167-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true}>
167+
<HydraAdmin entrypoint="https://demo.api-platform.com">
168168
<ResourceGuesser edit={ReviewsEdit}/>
169169
{/* ... */}
170170
</HydraAdmin>

admin/file-upload.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MediaObjectsCreate = props => (
2525
);
2626

2727
export default () => (
28-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true}>
28+
<HydraAdmin entrypoint="https://demo.api-platform.com">
2929
<ResourceGuesser name="media_objects" create={MediaObjectsCreate} />
3030
{/* ... */}
3131
</HydraAdmin>

admin/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { HydraAdmin } from "@api-platform/admin";
3535
// Replace with your own API entrypoint
3636
// For instance if https://example.com/api/books is the path to the collection of book resources, then the entrypoint is https://example.com/api
3737
export default () => (
38-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true} />
38+
<HydraAdmin entrypoint="https://demo.api-platform.com" />
3939
);
4040
```
4141

admin/handling-relations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const BooksList = (props) => (
9898
);
9999

100100
export default () => (
101-
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT} mercure={true}>
101+
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT}>
102102
<ResourceGuesser
103103
name="books"
104104
list={BooksList}
@@ -128,7 +128,7 @@ const BooksList = (props) => (
128128
);
129129

130130
export default () => (
131-
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT} mercure={true}>
131+
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT}>
132132
<ResourceGuesser
133133
name="books"
134134
list={BooksList}
@@ -256,7 +256,7 @@ const ReviewsEdit = props => (
256256
);
257257

258258
export default () => (
259-
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT} mercure={true}>
259+
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT}>
260260
<ResourceGuesser
261261
name="reviews"
262262
create={ReviewsCreate}
@@ -318,7 +318,7 @@ const ReviewsEdit = props => (
318318
);
319319

320320
export default () => (
321-
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT} mercure={true}>
321+
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT}>
322322
<ResourceGuesser
323323
name="reviews"
324324
create={ReviewsCreate}

admin/real-time-mercure.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ Updates are received by using the `useMercureSubscription` hook in the `ListGues
66

77
To enable Mercure server-side, see the [related documentation](../core/mercure.md).
88

9-
To receive API updates from the hub, you need to explicitly enable Mercure in the Hydra data provider.
10-
To do so, you can either do it with a prop in the `<HydraAdmin>` component:
9+
Once enabled, API Platform Admin will automatically detect that Mercure is enabled and will discover the Mercure hub URL by itself.
10+
11+
## Advanced Configuration
12+
13+
If you want to customize the default Mercure configuration, you can either do it with a prop in the `<HydraAdmin>` component:
1114

1215
```javascript
1316
import { HydraAdmin } from "@api-platform/admin";
1417

1518
export default () => (
16-
<HydraAdmin entrypoint="https://demo.api-platform.com" mercure={true} />
19+
<HydraAdmin
20+
entrypoint="https://demo.api-platform.com"
21+
mercure={{ hub: "https://mercure.rocks/hub" }}
22+
/>
1723
);
1824
```
1925

@@ -27,17 +33,11 @@ const dataProvider = baseHydraDataProvider({
2733
entrypoint,
2834
httpClient: fetchHydra,
2935
apiDocumentationParser: parseHydraDocumentation,
30-
mercure: true,
36+
mercure: { hub: "https://mercure.rocks/hub" },
3137
});
3238
```
3339

34-
If you want to disable Mercure, use `false` for the `mercure` value instead.
35-
36-
## Advanced Configuration
37-
38-
The `mercure` value can also takes an object to customize the default configuration.
39-
40-
The object has the following properties:
41-
- `hub`: the URL to your Mercure hub (default value: entrypoint/.well-known/mercure)
40+
The `mercure` object can take the following properties:
41+
- `hub`: the URL to your Mercure hub (default value: null ; when null it will be discovered by using API responses)
4242
- `jwt`: a subscriber JWT to access your Mercure hub (default value: null)
4343
- `topicUrl`: the topic URL of your resources (default value: entrypoint)

0 commit comments

Comments
 (0)