diff --git a/bin/dev-router.php b/bin/dev-router.php index c1f1c8c..0871238 100644 --- a/bin/dev-router.php +++ b/bin/dev-router.php @@ -8,12 +8,6 @@ use Cake\Http\ServerRequestFactory; use Glaze\Application; use Glaze\Config\ProjectConfigurationReader; -use Glaze\Http\DevPageRequestHandler; -use Glaze\Http\Middleware\ContentAssetMiddleware; -use Glaze\Http\Middleware\ErrorHandlingMiddleware; -use Glaze\Http\Middleware\PublicAssetMiddleware; -use Glaze\Http\Middleware\StaticAssetMiddleware; -use Glaze\Http\StaticPageRequestHandler; require dirname(__DIR__) . '/vendor/autoload.php'; @@ -30,31 +24,19 @@ $includeDrafts = getenv('GLAZE_INCLUDE_DRAFTS') === '1'; $staticMode = getenv('GLAZE_STATIC_MODE') === '1'; +$debug = getenv('GLAZE_DEBUG') === '1'; $application = new Application(); $application->bootstrap(); -$container = $application->getContainer(); (new ProjectConfigurationReader())->read($projectRoot); Configure::write('projectRoot', $projectRoot); +Configure::write('debug', $debug); if ($includeDrafts) { Configure::write('build.drafts', true); } -/** @var \Glaze\Http\Middleware\PublicAssetMiddleware $publicAssetMiddleware */ -$publicAssetMiddleware = $container->get(PublicAssetMiddleware::class); -/** @var \Glaze\Http\Middleware\StaticAssetMiddleware $staticAssetMiddleware */ -$staticAssetMiddleware = $container->get(StaticAssetMiddleware::class); -/** @var \Glaze\Http\Middleware\ContentAssetMiddleware $contentAssetMiddleware */ -$contentAssetMiddleware = $container->get(ContentAssetMiddleware::class); - -if ($staticMode) { - /** @var \Glaze\Http\StaticPageRequestHandler $fallbackHandler */ - $fallbackHandler = $container->get(StaticPageRequestHandler::class); -} else { - /** @var \Glaze\Http\DevPageRequestHandler $fallbackHandler */ - $fallbackHandler = $container->get(DevPageRequestHandler::class); -} +$fallbackHandler = $application->fallbackHandler($staticMode); $requestMethod = $_SERVER['REQUEST_METHOD'] ?? null; if (!is_string($requestMethod) || $requestMethod === '') { @@ -76,11 +58,7 @@ $request = $request->withQueryParams($queryParams); } -$queue = new MiddlewareQueue(); -$queue->add(new ErrorHandlingMiddleware(true)); -$queue->add($publicAssetMiddleware); -$queue->add($staticAssetMiddleware); -$queue->add($contentAssetMiddleware); +$queue = $application->middleware(new MiddlewareQueue(), $staticMode); $response = (new Runner())->run($queue, $request, $fallbackHandler); diff --git a/docs/content/reference/commands.dj b/docs/content/reference/commands.dj index fb52188..336d3cd 100644 --- a/docs/content/reference/commands.dj +++ b/docs/content/reference/commands.dj @@ -174,6 +174,7 @@ Options: - `--static` serve prebuilt `public/` - `--build` prebuild before static serve (`--static` required) - `--drafts` include drafts for static mode +- `--debug` enable debug mode - `--vite` enable Vite integration in live mode - `--vite-host ` Vite host (default `127.0.0.1`) - `--vite-port ` Vite port (default `5173`) diff --git a/docs/content/reference/recipes.dj b/docs/content/reference/recipes.dj index 989238a..441e277 100644 --- a/docs/content/reference/recipes.dj +++ b/docs/content/reference/recipes.dj @@ -7,16 +7,17 @@ weight: 50 Short, copy-paste patterns for common real-world needs. -## Environment-aware templates with `$debug` +## Environment-aware templates with `$this->isLiveMode()` -Every template receives a `$debug` boolean that is `true` when Glaze is running in -`glaze serve` (development) mode and `false` during `glaze build` (production). +Inside templates, `$this` is a `SiteContext` object. Use `$this->isLiveMode()` to +detect whether Glaze is running in `glaze serve` (live mode) or `glaze build` +(static build mode). This lets you keep a single template codebase while varying content by environment — no separate config files required. ::: info -`$debug` maps 1-to-1 with the `glaze serve` / `glaze build` distinction +`$this->isLiveMode()` maps 1-to-1 with the `glaze serve` / `glaze build` distinction — it is not affected by your NEON config, OS environment variables, or Vite settings. ::: @@ -26,7 +27,7 @@ Keep your development credentials out of production builds (and vice versa): ```php isLiveMode() ? 'pk_test_xxxxxxxxxxxxxxxx' // development key : 'pk_live_xxxxxxxxxxxxxxxx'; // production key ?> @@ -48,7 +49,7 @@ site: ```php isLiveMode() ? $site->siteMeta('apiKeyDev') : $site->siteMeta('apiKeyLive'); ?> @@ -63,7 +64,7 @@ Emit the GTM snippet only when generating the static build so analytics data is never polluted by local development traffic: ```php - +isLiveMode()): ?>