Skip to content

Commit 1a658af

Browse files
committed
Register virtual routes through the service container
1 parent 52fd8fd commit 1a658af

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Desilva\Microserve\JsonResponse;
88
use Desilva\Microserve\Request;
99
use Desilva\Microserve\Response;
10+
use Hyde\RealtimeCompiler\RealtimeCompiler;
1011
use Hyde\RealtimeCompiler\Actions\AssetFileLocator;
1112
use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses;
1213
use Hyde\RealtimeCompiler\Models\FileObject;
@@ -20,13 +21,6 @@ class Router
2021

2122
protected Request $request;
2223

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

4135
$this->bootApplication();
4236

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-
}
37+
$virtualRoutes = app(RealtimeCompiler::class)->getVirtualRoutes();
38+
39+
if (isset($virtualRoutes[$this->request->path])) {
40+
return $virtualRoutes[$this->request->path];
4941
}
5042

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

0 commit comments

Comments
 (0)