From 622c038a87abe34d88fa3d3ec25b987cc3898602 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 7 Nov 2023 20:57:39 +0100 Subject: [PATCH 1/2] Buffer page router contents This allows us to inject code before serving but without it affecting any compiled source saved to disk --- packages/realtime-compiler/src/Routing/PageRouter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/realtime-compiler/src/Routing/PageRouter.php b/packages/realtime-compiler/src/Routing/PageRouter.php index a7754cc19be..9981e9a6651 100644 --- a/packages/realtime-compiler/src/Routing/PageRouter.php +++ b/packages/realtime-compiler/src/Routing/PageRouter.php @@ -63,12 +63,14 @@ protected function getHtml(HydePage $page): string } if (config('hyde.server.save_preview')) { - return file_get_contents(StaticPageBuilder::handle($page)); + $contents = file_get_contents(StaticPageBuilder::handle($page)); } else { Hyde::shareViewData($page); - return $page->compile(); + $contents = $page->compile(); } + + return $contents; } public static function handle(Request $request): Response From f822b294c40ac604e8218c0f5a52b427e63f9051 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 13 Nov 2023 20:08:24 +0100 Subject: [PATCH 2/2] Make token helper method static --- packages/realtime-compiler/src/Http/BaseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/realtime-compiler/src/Http/BaseController.php b/packages/realtime-compiler/src/Http/BaseController.php index 385e2d534a4..991c8f694bb 100644 --- a/packages/realtime-compiler/src/Http/BaseController.php +++ b/packages/realtime-compiler/src/Http/BaseController.php @@ -86,7 +86,7 @@ protected function isRequestMadeFromLocalhost(): bool return in_array($requestIp, $allowedIps, true); } - protected function generateCSRFToken(): string + protected static function generateCSRFToken(): string { if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32));