20
20
use Desilva \Microserve \JsonResponse ;
21
21
use Hyde \Support \Filesystem \MediaFile ;
22
22
use Illuminate \Support \Facades \Process ;
23
- use Hyde \RealtimeCompiler \ConsoleOutput ;
24
23
use Hyde \Framework \Actions \StaticPageBuilder ;
25
24
use Hyde \Framework \Actions \AnonymousViewCompiler ;
26
- use Desilva \Microserve \Request ;
27
25
use Composer \InstalledVersions ;
28
26
use Hyde \Framework \Actions \CreatesNewPageSourceFile ;
29
27
use Hyde \Framework \Exceptions \FileConflictException ;
@@ -37,8 +35,8 @@ class DashboardController extends BaseController
37
35
{
38
36
public string $ title ;
39
37
40
- protected Request $ request ;
41
- protected ConsoleOutput $ console ;
38
+ protected bool $ withConsoleOutput = true ;
39
+
42
40
protected JsonResponse $ response ;
43
41
44
42
protected bool $ isAsync = false ;
@@ -54,12 +52,9 @@ class DashboardController extends BaseController
54
52
55
53
public function __construct ()
56
54
{
57
- $ this ->title = config ('hyde.name ' ).' - Dashboard ' ;
58
- $ this ->request = Request::capture ();
55
+ parent ::__construct ();
59
56
60
- if (((bool ) env ('HYDE_SERVER_REQUEST_OUTPUT ' , false )) === true ) {
61
- $ this ->console = new ConsoleOutput ();
62
- }
57
+ $ this ->title = config ('hyde.name ' ).' - Dashboard ' ;
63
58
64
59
$ this ->loadFlashData ();
65
60
@@ -451,38 +446,13 @@ protected static function getPackageVersion(string $packageName): string
451
446
return $ prettyVersion ?? 'unreleased ' ;
452
447
}
453
448
454
- protected function shouldUnsafeRequestBeBlocked (): bool
455
- {
456
- // As the dashboard is not password-protected, and it can make changes to the file system,
457
- // we block any requests that are not coming from the host machine. While we are clear
458
- // in the documentation that the realtime compiler should only be used for local
459
- // development, we still want to be extra careful in case someone forgets.
460
-
461
- $ requestIp = $ _SERVER ['REMOTE_ADDR ' ];
462
- $ allowedIps = ['::1 ' , '127.0.0.1 ' , 'localhost ' ];
463
-
464
- return ! in_array ($ requestIp , $ allowedIps , true );
465
- }
466
-
467
449
protected function setJsonResponse (int $ statusCode , string $ body ): void
468
450
{
469
451
$ this ->response = new JsonResponse ($ statusCode , $ this ->matchStatusCode ($ statusCode ), [
470
452
'body ' => $ body ,
471
453
]);
472
454
}
473
455
474
- protected function sendJsonErrorResponse (int $ statusCode , string $ message ): JsonResponse
475
- {
476
- return new JsonResponse ($ statusCode , $ this ->matchStatusCode ($ statusCode ), [
477
- 'error ' => $ message ,
478
- ]);
479
- }
480
-
481
- protected function abort (int $ code , string $ message ): never
482
- {
483
- throw new HttpException ($ code , $ message );
484
- }
485
-
486
456
protected function findGeneralOpenBinary (): string
487
457
{
488
458
return match (PHP_OS_FAMILY ) {
@@ -496,28 +466,8 @@ protected function findGeneralOpenBinary(): string
496
466
};
497
467
}
498
468
499
- protected function matchStatusCode (int $ statusCode ): string
500
- {
501
- return match ($ statusCode ) {
502
- 200 => 'OK ' ,
503
- 201 => 'Created ' ,
504
- 400 => 'Bad Request ' ,
505
- 403 => 'Forbidden ' ,
506
- 404 => 'Not Found ' ,
507
- 409 => 'Conflict ' ,
508
- default => 'Internal Server Error ' ,
509
- };
510
- }
511
-
512
469
protected function hasAsyncHeaders (): bool
513
470
{
514
471
return (getallheaders ()['X-RC-Handler ' ] ?? getallheaders ()['x-rc-handler ' ] ?? null ) === 'Async ' ;
515
472
}
516
-
517
- protected function writeToConsole (string $ message , string $ context = 'dashboard ' ): void
518
- {
519
- if (isset ($ this ->console )) {
520
- $ this ->console ->printMessage ($ message , $ context );
521
- }
522
- }
523
473
}
0 commit comments