Skip to content

Instantly share code, notes, and snippets.

@simonhamp
Last active May 28, 2024 08:47
Show Gist options
  • Save simonhamp/d41cd48f6221ff2f4843e7b0369c359d to your computer and use it in GitHub Desktop.
Save simonhamp/d41cd48f6221ff2f4843e7b0369c359d to your computer and use it in GitHub Desktop.
Run anything you like through Laravel Herd

Run Static Sites through Laravel Herd

Got a React app that you want to serve via HTTPS so you can test things like Websockets and CORS issues locally?

Throw this LocalValetDriver.php into the root of the project and Herd will just serve the static files for you.

Switch on SSL for that site in Herd's settings or command line and you've got a fully working app just like in prod.

No other tools required. No self-signed certs to generate.

You then just need to explicitly visit the file path in your browser.

Let's say you have a project called react-app. As long as Herd knows about this, you'll be able to access it in your browser at something like http://react-app.test/, without needing to run a Vite or Webpack server.

Assuming it has a public/index.html file in it, after putting this Valet driver into the root, you'll be able to visit http://react-app.test/index.html and see the page load up.

Now turn on SSL and you can load it via https://react-app.test/index.html

This is a very basic version of one of the default Valet drivers. Because Herd is built around Valet, you can use all of these and more.

<?php
use Valet\Drivers\ValetDriver;
class LocalValetDriver extends ValetDriver
{
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return true;
}
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
{
return '';
}
public function isStaticFile(string $sitePath, string $siteName, string $uri)
{
return $sitePath.'/public'.$uri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment