| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
-
- use Valet\Drivers\ValetDriver;
-
- /** Serve the compiled Vite storefront through Herd, including SPA deep links. */
- class LocalValetDriver extends ValetDriver
- {
- public function serves(string $sitePath, string $siteName, string $uri): bool
- {
- return is_file($sitePath.'/package.json');
- }
-
- public function isStaticFile(string $sitePath, string $siteName, string $uri)
- {
- $root = realpath($sitePath.'/dist');
- $file = $root ? realpath($root.'/'.ltrim($uri, '/')) : false;
-
- // Only expose compiled public files, never source or project configuration.
- if ($root && $file && str_starts_with($file, $root.DIRECTORY_SEPARATOR)
- && is_file($file) && !str_starts_with(basename($file), '.')) {
- return $file;
- }
-
- return false;
- }
-
- public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
- {
- // Missing assets must return 404 instead of an HTML response.
- if (pathinfo($uri, PATHINFO_EXTENSION) !== '' && $uri !== '/index.html') {
- return null;
- }
-
- $index = $sitePath.'/dist/index.html';
-
- return is_file($index) ? $index : null;
- }
- }
|