You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LocalValetDriver.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use Valet\Drivers\ValetDriver;
  3. /** Serve the compiled Vite storefront through Herd, including SPA deep links. */
  4. class LocalValetDriver extends ValetDriver
  5. {
  6. public function serves(string $sitePath, string $siteName, string $uri): bool
  7. {
  8. return is_file($sitePath.'/package.json');
  9. }
  10. public function isStaticFile(string $sitePath, string $siteName, string $uri)
  11. {
  12. $root = realpath($sitePath.'/dist');
  13. $file = $root ? realpath($root.'/'.ltrim($uri, '/')) : false;
  14. // Only expose compiled public files, never source or project configuration.
  15. if ($root && $file && str_starts_with($file, $root.DIRECTORY_SEPARATOR)
  16. && is_file($file) && !str_starts_with(basename($file), '.')) {
  17. return $file;
  18. }
  19. return false;
  20. }
  21. public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
  22. {
  23. // Missing assets must return 404 instead of an HTML response.
  24. if (pathinfo($uri, PATHINFO_EXTENSION) !== '' && $uri !== '/index.html') {
  25. return null;
  26. }
  27. $index = $sitePath.'/dist/index.html';
  28. return is_file($index) ? $index : null;
  29. }
  30. }