Skip to content

Commit 508625e

Browse files
committed
Register virtual routes through the service container
1 parent dad93d4 commit 508625e

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

packages/realtime-compiler/src/RealtimeCompilerServiceProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Hyde\RealtimeCompiler;
66

7+
use Desilva\Microserve\JsonResponse;
78
use Illuminate\Support\ServiceProvider;
89

910
class RealtimeCompilerServiceProvider extends ServiceProvider
@@ -17,6 +18,8 @@ public function register(): void
1718

1819
public function boot(): void
1920
{
20-
//
21+
$this->app->make(RealtimeCompiler::class)->registerVirtualRoute('/ping', new JsonResponse(200, 'OK', [
22+
'server' => 'Hyde/RealtimeCompiler',
23+
]));
2124
}
2225
}

packages/realtime-compiler/src/Routing/Router.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Hyde\RealtimeCompiler\Routing;
66

7-
use Desilva\Microserve\JsonResponse;
87
use Desilva\Microserve\Request;
98
use Desilva\Microserve\Response;
9+
use Hyde\RealtimeCompiler\RealtimeCompiler;
1010
use Hyde\RealtimeCompiler\Actions\AssetFileLocator;
1111
use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses;
1212
use Hyde\RealtimeCompiler\Models\FileObject;
@@ -20,13 +20,6 @@ class Router
2020

2121
protected Request $request;
2222

23-
/**
24-
* @deprecated This should be moved to the container.
25-
*/
26-
protected array $virtualRoutes = [
27-
'/ping',
28-
];
29-
3023
public function __construct(Request $request)
3124
{
3225
$this->request = $request;
@@ -40,12 +33,10 @@ public function handle(): Response
4033

4134
$this->bootApplication();
4235

43-
if (in_array($this->request->path, $this->virtualRoutes)) {
44-
if ($this->request->path === '/ping') {
45-
return new JsonResponse(200, 'OK', [
46-
'server' => 'Hyde/RealtimeCompiler',
47-
]);
48-
}
36+
$virtualRoutes = app(RealtimeCompiler::class)->getVirtualRoutes();
37+
38+
if (isset($virtualRoutes[$this->request->path])) {
39+
return $virtualRoutes[$this->request->path];
4940
}
5041

5142
return PageRouter::handle($this->request);

0 commit comments

Comments
 (0)