diff --git a/packages/realtime-compiler/src/Routing/Router.php b/packages/realtime-compiler/src/Routing/Router.php index 49aa7169d15..0dd9be9e97a 100644 --- a/packages/realtime-compiler/src/Routing/Router.php +++ b/packages/realtime-compiler/src/Routing/Router.php @@ -8,10 +8,13 @@ use Hyde\RealtimeCompiler\Actions\AssetFileLocator; use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses; use Hyde\RealtimeCompiler\Models\FileObject; +use Hyde\RealtimeCompiler\Concerns\InteractsWithLaravel; +use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex; class Router { use SendsErrorResponses; + use InteractsWithLaravel; protected Request $request; @@ -74,7 +77,11 @@ protected function proxyStatic(): Response $path = AssetFileLocator::find($this->request->path); if ($path === null) { - return $this->notFound(); + if ($this->request->path === '/docs/search.json') { + $path = $this->generateSearchIndex(); + } else { + return $this->notFound(); + } } $file = new FileObject($path); @@ -86,4 +93,18 @@ protected function proxyStatic(): Response 'Content-Length' => $file->getContentLength(), ]); } + + /** + * Generate and serve the documentation search index. + * + * Note that this only gets called if the index is not + * yet generated. It does not keep track of if the + * index is up-to-date or not. + */ + protected function generateSearchIndex(): string + { + $this->bootApplication(); + + return GeneratesDocumentationSearchIndex::handle(); + } }