You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(symfony): document the API Platform CLI installer
Rework the Symfony getting-started and Caddy guides around the new
`api-platform` CLI (api-platform/installer) instead of the legacy distribution.
- symfony/index.md: install the CLI as a static binary or via
`composer global require api-platform/installer`; scaffold with
`api-platform <name> --framework=symfony` (there is no `new` subcommand).
Document the standalone Next.js PWA model (runs on :3000, talks to the API
cross-origin via CORS) instead of a containerized single-domain PWA. Mention
`--with-agents` (generates AGENTS.md / CLAUDE.md).
- symfony/caddy.md: describe the Caddyfile actually shipped by symfony-docker
(FrankenPHP worker, @phproute) and the Hydra+Mercure Link header injected
through CADDY_SERVER_EXTRA_DIRECTIVES. Move the single-domain API+PWA proxy
(route{}, @pwa, PWA_UPSTREAM) into an opt-in section.
- core/getting-started.md, laravel/index.md: use `api-platform <name>`
(drop the non-existent `new` subcommand).
[The API Platform Symfony variant](index.md), when generated with Docker, is shipped with
4
-
[the Caddy web server](https://caddyserver.com). The build contains the
5
-
[Mercure](../core/mercure.md) and the [Vulcain](https://vulcain.rocks) Caddy modules.
3
+
When you scaffold a project with the [API Platform CLI](index.md), the Symfony application is built
4
+
on top of [`symfony-docker`](https://github.com/dunglas/symfony-docker), which ships
5
+
[the Caddy web server](https://caddyserver.com) running [FrankenPHP](https://frankenphp.dev). The
6
+
build contains the [Mercure](../core/mercure.md) and the [Vulcain](https://vulcain.rocks) Caddy
7
+
modules.
6
8
7
-
Caddy is positioned in front of the web API and of the Progressive Web App (PWA). It routes requests
8
-
to either service depending on the value of the `Accept` HTTP header or the path of the request.
9
+
The Caddyfile lives at `api/frankenphp/Caddyfile`.
9
10
10
-
Using the same domain to serve the API and the PWA
11
-
[improves performance by preventing unnecessary CORS preflight requests and encourages embracing the REST principles](https://dunglas.fr/2022/01/preventing-cors-preflight-requests-using-content-negotiation/).
11
+
## How the CLI Serves the API and the PWA
12
12
13
-
## Why `route {}` Is Required
13
+
By default the API and the Progressive Web App (PWA) are served **separately**:
14
+
15
+
- Caddy serves the **API** on `https://localhost`.
16
+
- When you scaffold with `--with-pwa`, the Next.js application runs **standalone** with `pnpm dev`
17
+
on `http://localhost:3000`. It calls the API cross-origin using the `NEXT_PUBLIC_API_ENTRYPOINT`
18
+
value written to `pwa/.env.local`, and the CLI installs and configures
19
+
[`nelmio/cors-bundle`](https://github.com/nelmio/NelmioCorsBundle) on the API so those
20
+
cross-origin requests are allowed.
21
+
22
+
This keeps the two applications independent and requires no Caddy configuration. If you prefer to
23
+
serve both on the **same domain** through Caddy — which
24
+
[improves performance by preventing unnecessary CORS preflight requests and encourages embracing the REST principles](https://dunglas.fr/2022/01/preventing-cors-preflight-requests-using-content-negotiation/)
25
+
— see
26
+
[Serving the API and the PWA on the Same Domain](#serving-the-api-and-the-pwa-on-the-same-domain)
27
+
below.
28
+
29
+
## The Shipped Caddyfile
30
+
31
+
Out of the box, `api/frankenphp/Caddyfile` routes every request to the PHP application. The relevant
32
+
part of the site block looks like this:
33
+
34
+
```caddy
35
+
{$SERVER_NAME:localhost} {
36
+
root /app/public
37
+
encode zstd br gzip
38
+
39
+
mercure {
40
+
# ...Mercure hub configuration...
41
+
}
42
+
43
+
vulcain
44
+
45
+
# Extra directives injected by the CLI (see "The Link Header" below)
46
+
{$CADDY_SERVER_EXTRA_DIRECTIVES}
47
+
48
+
@phpRoute {
49
+
not path /.well-known/mercure*
50
+
not file {path}
51
+
}
52
+
rewrite @phpRoute index.php
53
+
54
+
@frontController path index.php
55
+
php @frontController {
56
+
worker {
57
+
file ./public/index.php
58
+
}
59
+
}
60
+
61
+
file_server {
62
+
hide *.php
63
+
}
64
+
}
65
+
```
66
+
67
+
Any request that is not an existing static file and is not a Mercure subscription is rewritten to
68
+
`index.php` and handled by Symfony through the FrankenPHP worker.
69
+
70
+
## The `Link` Header
71
+
72
+
The CLI adds a Hydra + Mercure `Link` header to every response. Rather than editing the Caddyfile
73
+
directly, it injects the directive through the `CADDY_SERVER_EXTRA_DIRECTIVES` environment variable
0 commit comments