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>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
# php-qml framework skeleton — FrankenPHP / Caddy / Mercure config (dev mode).
|
||||
# php-qml framework skeleton — FrankenPHP / Caddy / Mercure config.
|
||||
#
|
||||
# Run from the skeleton/symfony/ directory so relative `php_server` paths
|
||||
# resolve correctly: cd framework/skeleton/symfony && frankenphp run --watch
|
||||
# --config ../Caddyfile.
|
||||
# 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.
|
||||
{
|
||||
auto_https off
|
||||
admin off
|
||||
@@ -12,16 +15,17 @@
|
||||
}
|
||||
|
||||
http://127.0.0.1:{$PORT:8765} {
|
||||
root * public/
|
||||
root * public/
|
||||
encode gzip
|
||||
|
||||
mercure {
|
||||
transport local
|
||||
# In bundled mode the host generates a fresh per-session JWT;
|
||||
# requires >= 256 bits, hence the long dev value.
|
||||
publisher_jwt dev_php_qml_bridge_jwt_secret_at_least_256_bits_long_for_lcobucci
|
||||
subscriber_jwt dev_php_qml_bridge_jwt_secret_at_least_256_bits_long_for_lcobucci
|
||||
anonymous
|
||||
# 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}
|
||||
anonymous
|
||||
publish_origins *
|
||||
cors_origins *
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user