Files
php-qml/framework/skeleton/Caddyfile

40 lines
1.1 KiB
Caddyfile
Raw Normal View History

Phase 4a sub-commit 1: bundled-mode startup in BackendConnection Auto-detected on construction: - BRIDGE_URL env set → dev mode (today's behaviour, unchanged). - BRIDGE_URL unset → bundled mode: BackendConnection now 1. Resolves the user app data dir (QStandardPaths::AppDataLocation, ~/.local/share/<org>/<app> on Linux) and ensures var/, var/log/, var/cache/ exist there. 2. Generates a per-session 32-byte URL-safe token and a 48-byte Mercure JWT secret. 3. Runs `frankenphp php-cli bin/console doctrine:migrations:migrate -n` against the user's DATABASE_URL with a 60s timeout. 4. Spawns FrankenPHP via QProcess with BRIDGE_TOKEN/MERCURE_*/PORT in the env, prctl(PR_SET_PDEATHSIG, SIGTERM) on the child, and a supervisor that re-spawns up to 5 times on unexpected exit. Each restart fires tokenRotated(newToken). Path resolution defaults to applicationDirPath() + bin/frankenphp, applicationDirPath() + symfony, applicationDirPath() + Caddyfile, with both `/../share/<app>/...` and `/../usr/share/<app>/...` fallbacks for AppImage-style layouts. All three are overridable via BRIDGE_FRANKENPHP_BIN / BRIDGE_SYMFONY_DIR / BRIDGE_CADDYFILE env vars. Caddyfiles in skeleton + example now use {$VAR:default} substitution for PORT and the Mercure JWT keys, so the same Caddyfile works in both modes. Dev defaults match symfony/.env. restart() in bundled mode re-spawns the child (resets the supervisor counter); in dev mode it stays a probe-only no-op. Smoke-tested locally with `BRIDGE_FRANKENPHP_BIN=… BRIDGE_SYMFONY_DIR=… BRIDGE_CADDYFILE=… ./build/qml/todo` (no BRIDGE_URL): bundled mode created ~/.local/share/php-qml/todo/var/data.sqlite, ran the migration, spawned FrankenPHP, served /healthz, accepted a POST /api/todos with the per-session bearer. Dev mode (`make dev`) still works unchanged. Includes a `phpqml.bridge.bundled` Q_LOGGING_CATEGORY so failures surface to the user; enable with QT_LOGGING_RULES='phpqml.bridge.bundled.*=true'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 17:00:13 +02:00
# php-qml framework skeleton — FrankenPHP / Caddy / Mercure config.
Phase 1 sub-commit 6: skeleton wiring — make dev runs end-to-end Symfony app under framework/skeleton/symfony/: minimal bin/console, public/index.php, MicroKernel-based src/Kernel.php, services.yaml, framework/security/mercure config, and a demo App\Controller\PingController that GETs /api/ping (returning JSON pong) and republishes the same payload to the Mercure topic app://ping. composer.json uses a path repository to symlink the bundle from ../../php so local edits are picked up live. QML app under framework/skeleton/qml/: top-level CMake that add_subdirectory's framework/qml, a main.cpp that creates the Qt process, runs SingleInstance.acquireOrForward before any QML loads, exposes SingleInstance via context property, and loadFromModule's Skeleton.Main. Main.qml uses BackendConnection / RestClient / MercureClient from PhpQml.Bridge and renders status dots, a Ping button, and an event log. Caddyfile binds 127.0.0.1:8765, enables in-memory Mercure with a 256-bit dev JWT (matches symfony/.env, lcobucci/jwt requires this). Makefile wraps build / dev / doctor / clean; scripts/dev.sh starts FrankenPHP --watch and the Qt host together with explicit PID-based teardown (process-group `kill 0` proved unreliable when frankenphp's watch fork reparented). Bug fixes uncovered in this sub-commit: - SingleInstance.acquireOrForward: probe-first, then removeServer + retry-listen. The original loop-with-removeServer-after-failed-bind silently exited on stale sockets from prior runs. - Main.qml: MercureClient does NOT inherit BackendConnection.token — Mercure subscribes anonymously in dev (Caddyfile), and forwarding the bridge bearer made it 401-loop. - /api/ping was 500ing because the dev MERCURE_JWT_SECRET was 144 bits; bumped to 64-char (>=256 bit) to satisfy lcobucci/jwt. - Linked the framework lib (php_qml_bridge) explicitly in addition to the QML plugin so SingleInstance.h resolves. - Auto-generated config/reference.php gitignored. Smoke verified offscreen: /healthz 200, /api/ping 200, 1 publish, 1 subscriber, zero 401s, clean shutdown with no zombies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 01:50:16 +02:00
#
Phase 4a sub-commit 1: bundled-mode startup in BackendConnection Auto-detected on construction: - BRIDGE_URL env set → dev mode (today's behaviour, unchanged). - BRIDGE_URL unset → bundled mode: BackendConnection now 1. Resolves the user app data dir (QStandardPaths::AppDataLocation, ~/.local/share/<org>/<app> on Linux) and ensures var/, var/log/, var/cache/ exist there. 2. Generates a per-session 32-byte URL-safe token and a 48-byte Mercure JWT secret. 3. Runs `frankenphp php-cli bin/console doctrine:migrations:migrate -n` against the user's DATABASE_URL with a 60s timeout. 4. Spawns FrankenPHP via QProcess with BRIDGE_TOKEN/MERCURE_*/PORT in the env, prctl(PR_SET_PDEATHSIG, SIGTERM) on the child, and a supervisor that re-spawns up to 5 times on unexpected exit. Each restart fires tokenRotated(newToken). Path resolution defaults to applicationDirPath() + bin/frankenphp, applicationDirPath() + symfony, applicationDirPath() + Caddyfile, with both `/../share/<app>/...` and `/../usr/share/<app>/...` fallbacks for AppImage-style layouts. All three are overridable via BRIDGE_FRANKENPHP_BIN / BRIDGE_SYMFONY_DIR / BRIDGE_CADDYFILE env vars. Caddyfiles in skeleton + example now use {$VAR:default} substitution for PORT and the Mercure JWT keys, so the same Caddyfile works in both modes. Dev defaults match symfony/.env. restart() in bundled mode re-spawns the child (resets the supervisor counter); in dev mode it stays a probe-only no-op. Smoke-tested locally with `BRIDGE_FRANKENPHP_BIN=… BRIDGE_SYMFONY_DIR=… BRIDGE_CADDYFILE=… ./build/qml/todo` (no BRIDGE_URL): bundled mode created ~/.local/share/php-qml/todo/var/data.sqlite, ran the migration, spawned FrankenPHP, served /healthz, accepted a POST /api/todos with the per-session bearer. Dev mode (`make dev`) still works unchanged. Includes a `phpqml.bridge.bundled` Q_LOGGING_CATEGORY so failures surface to the user; enable with QT_LOGGING_RULES='phpqml.bridge.bundled.*=true'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 17:00:13 +02:00
# Works in both run modes:
# - dev mode → env unset, defaults below match symfony/.env
# - bundled mode → BackendConnection sets PORT and MERCURE_*_JWT_KEY
# before launching FrankenPHP.
#
# Caddyfile {$VAR:default} syntax substitutes env vars at parse time.
Phase 1 sub-commit 6: skeleton wiring — make dev runs end-to-end Symfony app under framework/skeleton/symfony/: minimal bin/console, public/index.php, MicroKernel-based src/Kernel.php, services.yaml, framework/security/mercure config, and a demo App\Controller\PingController that GETs /api/ping (returning JSON pong) and republishes the same payload to the Mercure topic app://ping. composer.json uses a path repository to symlink the bundle from ../../php so local edits are picked up live. QML app under framework/skeleton/qml/: top-level CMake that add_subdirectory's framework/qml, a main.cpp that creates the Qt process, runs SingleInstance.acquireOrForward before any QML loads, exposes SingleInstance via context property, and loadFromModule's Skeleton.Main. Main.qml uses BackendConnection / RestClient / MercureClient from PhpQml.Bridge and renders status dots, a Ping button, and an event log. Caddyfile binds 127.0.0.1:8765, enables in-memory Mercure with a 256-bit dev JWT (matches symfony/.env, lcobucci/jwt requires this). Makefile wraps build / dev / doctor / clean; scripts/dev.sh starts FrankenPHP --watch and the Qt host together with explicit PID-based teardown (process-group `kill 0` proved unreliable when frankenphp's watch fork reparented). Bug fixes uncovered in this sub-commit: - SingleInstance.acquireOrForward: probe-first, then removeServer + retry-listen. The original loop-with-removeServer-after-failed-bind silently exited on stale sockets from prior runs. - Main.qml: MercureClient does NOT inherit BackendConnection.token — Mercure subscribes anonymously in dev (Caddyfile), and forwarding the bridge bearer made it 401-loop. - /api/ping was 500ing because the dev MERCURE_JWT_SECRET was 144 bits; bumped to 64-char (>=256 bit) to satisfy lcobucci/jwt. - Linked the framework lib (php_qml_bridge) explicitly in addition to the QML plugin so SingleInstance.h resolves. - Auto-generated config/reference.php gitignored. Smoke verified offscreen: /healthz 200, /api/ping 200, 1 publish, 1 subscriber, zero 401s, clean shutdown with no zombies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 01:50:16 +02:00
{
auto_https off
admin off
frankenphp
order php_server before respond
order mercure after encode
}
Phase 4a sub-commit 1: bundled-mode startup in BackendConnection Auto-detected on construction: - BRIDGE_URL env set → dev mode (today's behaviour, unchanged). - BRIDGE_URL unset → bundled mode: BackendConnection now 1. Resolves the user app data dir (QStandardPaths::AppDataLocation, ~/.local/share/<org>/<app> on Linux) and ensures var/, var/log/, var/cache/ exist there. 2. Generates a per-session 32-byte URL-safe token and a 48-byte Mercure JWT secret. 3. Runs `frankenphp php-cli bin/console doctrine:migrations:migrate -n` against the user's DATABASE_URL with a 60s timeout. 4. Spawns FrankenPHP via QProcess with BRIDGE_TOKEN/MERCURE_*/PORT in the env, prctl(PR_SET_PDEATHSIG, SIGTERM) on the child, and a supervisor that re-spawns up to 5 times on unexpected exit. Each restart fires tokenRotated(newToken). Path resolution defaults to applicationDirPath() + bin/frankenphp, applicationDirPath() + symfony, applicationDirPath() + Caddyfile, with both `/../share/<app>/...` and `/../usr/share/<app>/...` fallbacks for AppImage-style layouts. All three are overridable via BRIDGE_FRANKENPHP_BIN / BRIDGE_SYMFONY_DIR / BRIDGE_CADDYFILE env vars. Caddyfiles in skeleton + example now use {$VAR:default} substitution for PORT and the Mercure JWT keys, so the same Caddyfile works in both modes. Dev defaults match symfony/.env. restart() in bundled mode re-spawns the child (resets the supervisor counter); in dev mode it stays a probe-only no-op. Smoke-tested locally with `BRIDGE_FRANKENPHP_BIN=… BRIDGE_SYMFONY_DIR=… BRIDGE_CADDYFILE=… ./build/qml/todo` (no BRIDGE_URL): bundled mode created ~/.local/share/php-qml/todo/var/data.sqlite, ran the migration, spawned FrankenPHP, served /healthz, accepted a POST /api/todos with the per-session bearer. Dev mode (`make dev`) still works unchanged. Includes a `phpqml.bridge.bundled` Q_LOGGING_CATEGORY so failures surface to the user; enable with QT_LOGGING_RULES='phpqml.bridge.bundled.*=true'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 17:00:13 +02:00
http://127.0.0.1:{$PORT:8765} {
Phase 1 sub-commit 6: skeleton wiring — make dev runs end-to-end Symfony app under framework/skeleton/symfony/: minimal bin/console, public/index.php, MicroKernel-based src/Kernel.php, services.yaml, framework/security/mercure config, and a demo App\Controller\PingController that GETs /api/ping (returning JSON pong) and republishes the same payload to the Mercure topic app://ping. composer.json uses a path repository to symlink the bundle from ../../php so local edits are picked up live. QML app under framework/skeleton/qml/: top-level CMake that add_subdirectory's framework/qml, a main.cpp that creates the Qt process, runs SingleInstance.acquireOrForward before any QML loads, exposes SingleInstance via context property, and loadFromModule's Skeleton.Main. Main.qml uses BackendConnection / RestClient / MercureClient from PhpQml.Bridge and renders status dots, a Ping button, and an event log. Caddyfile binds 127.0.0.1:8765, enables in-memory Mercure with a 256-bit dev JWT (matches symfony/.env, lcobucci/jwt requires this). Makefile wraps build / dev / doctor / clean; scripts/dev.sh starts FrankenPHP --watch and the Qt host together with explicit PID-based teardown (process-group `kill 0` proved unreliable when frankenphp's watch fork reparented). Bug fixes uncovered in this sub-commit: - SingleInstance.acquireOrForward: probe-first, then removeServer + retry-listen. The original loop-with-removeServer-after-failed-bind silently exited on stale sockets from prior runs. - Main.qml: MercureClient does NOT inherit BackendConnection.token — Mercure subscribes anonymously in dev (Caddyfile), and forwarding the bridge bearer made it 401-loop. - /api/ping was 500ing because the dev MERCURE_JWT_SECRET was 144 bits; bumped to 64-char (>=256 bit) to satisfy lcobucci/jwt. - Linked the framework lib (php_qml_bridge) explicitly in addition to the QML plugin so SingleInstance.h resolves. - Auto-generated config/reference.php gitignored. Smoke verified offscreen: /healthz 200, /api/ping 200, 1 publish, 1 subscriber, zero 401s, clean shutdown with no zombies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 01:50:16 +02:00
root * public/
encode gzip
mercure {
transport local
Phase 4a sub-commit 1: bundled-mode startup in BackendConnection Auto-detected on construction: - BRIDGE_URL env set → dev mode (today's behaviour, unchanged). - BRIDGE_URL unset → bundled mode: BackendConnection now 1. Resolves the user app data dir (QStandardPaths::AppDataLocation, ~/.local/share/<org>/<app> on Linux) and ensures var/, var/log/, var/cache/ exist there. 2. Generates a per-session 32-byte URL-safe token and a 48-byte Mercure JWT secret. 3. Runs `frankenphp php-cli bin/console doctrine:migrations:migrate -n` against the user's DATABASE_URL with a 60s timeout. 4. Spawns FrankenPHP via QProcess with BRIDGE_TOKEN/MERCURE_*/PORT in the env, prctl(PR_SET_PDEATHSIG, SIGTERM) on the child, and a supervisor that re-spawns up to 5 times on unexpected exit. Each restart fires tokenRotated(newToken). Path resolution defaults to applicationDirPath() + bin/frankenphp, applicationDirPath() + symfony, applicationDirPath() + Caddyfile, with both `/../share/<app>/...` and `/../usr/share/<app>/...` fallbacks for AppImage-style layouts. All three are overridable via BRIDGE_FRANKENPHP_BIN / BRIDGE_SYMFONY_DIR / BRIDGE_CADDYFILE env vars. Caddyfiles in skeleton + example now use {$VAR:default} substitution for PORT and the Mercure JWT keys, so the same Caddyfile works in both modes. Dev defaults match symfony/.env. restart() in bundled mode re-spawns the child (resets the supervisor counter); in dev mode it stays a probe-only no-op. Smoke-tested locally with `BRIDGE_FRANKENPHP_BIN=… BRIDGE_SYMFONY_DIR=… BRIDGE_CADDYFILE=… ./build/qml/todo` (no BRIDGE_URL): bundled mode created ~/.local/share/php-qml/todo/var/data.sqlite, ran the migration, spawned FrankenPHP, served /healthz, accepted a POST /api/todos with the per-session bearer. Dev mode (`make dev`) still works unchanged. Includes a `phpqml.bridge.bundled` Q_LOGGING_CATEGORY so failures surface to the user; enable with QT_LOGGING_RULES='phpqml.bridge.bundled.*=true'. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 17:00:13 +02:00
# In bundled mode the host generates a fresh per-session JWT;
# in dev mode we fall back to the value from symfony/.env (must
# match it). lcobucci/jwt requires ≥256 bits.
publisher_jwt {$MERCURE_PUBLISHER_JWT_KEY:dev_php_qml_bridge_jwt_secret_at_least_256_bits_long_for_lcobucci}
subscriber_jwt {$MERCURE_SUBSCRIBER_JWT_KEY:dev_php_qml_bridge_jwt_secret_at_least_256_bits_long_for_lcobucci}
Phase 1 sub-commit 6: skeleton wiring — make dev runs end-to-end Symfony app under framework/skeleton/symfony/: minimal bin/console, public/index.php, MicroKernel-based src/Kernel.php, services.yaml, framework/security/mercure config, and a demo App\Controller\PingController that GETs /api/ping (returning JSON pong) and republishes the same payload to the Mercure topic app://ping. composer.json uses a path repository to symlink the bundle from ../../php so local edits are picked up live. QML app under framework/skeleton/qml/: top-level CMake that add_subdirectory's framework/qml, a main.cpp that creates the Qt process, runs SingleInstance.acquireOrForward before any QML loads, exposes SingleInstance via context property, and loadFromModule's Skeleton.Main. Main.qml uses BackendConnection / RestClient / MercureClient from PhpQml.Bridge and renders status dots, a Ping button, and an event log. Caddyfile binds 127.0.0.1:8765, enables in-memory Mercure with a 256-bit dev JWT (matches symfony/.env, lcobucci/jwt requires this). Makefile wraps build / dev / doctor / clean; scripts/dev.sh starts FrankenPHP --watch and the Qt host together with explicit PID-based teardown (process-group `kill 0` proved unreliable when frankenphp's watch fork reparented). Bug fixes uncovered in this sub-commit: - SingleInstance.acquireOrForward: probe-first, then removeServer + retry-listen. The original loop-with-removeServer-after-failed-bind silently exited on stale sockets from prior runs. - Main.qml: MercureClient does NOT inherit BackendConnection.token — Mercure subscribes anonymously in dev (Caddyfile), and forwarding the bridge bearer made it 401-loop. - /api/ping was 500ing because the dev MERCURE_JWT_SECRET was 144 bits; bumped to 64-char (>=256 bit) to satisfy lcobucci/jwt. - Linked the framework lib (php_qml_bridge) explicitly in addition to the QML plugin so SingleInstance.h resolves. - Auto-generated config/reference.php gitignored. Smoke verified offscreen: /healthz 200, /api/ping 200, 1 publish, 1 subscriber, zero 401s, clean shutdown with no zombies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 01:50:16 +02:00
anonymous
publish_origins *
cors_origins *
}
php_server
log {
output stderr
format console
}
}