1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 16:50:09 +01:00
Files
laravel-valet/cli/Valet/Drivers/LaravelValetDriver.php
Chris Brown fd35343f60 [v4] Fix ngrok.io proxy/forwarding detection
Fixes #1384

Since Valet 4 uses Ngrok v3, this change is needed to accommodate the change ngrok made:
> In ngrok v3 the `X-Original-Host` header was replaced with the more standard `X-Forwarded-Host` to better align with web standards.
> More Info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host

Credit to @streamingsystems for doing the legwork.

Co-authored-by: streamingsystems <streamingsystems@users.noreply.github.com>
2023-04-24 21:48:04 -04:00

58 lines
1.7 KiB
PHP

<?php
namespace Valet\Drivers;
class LaravelValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists($sitePath.'/public/index.php') &&
file_exists($sitePath.'/artisan');
}
/**
* Take any steps necessary before loading the front controller for this driver.
*/
public function beforeLoading(string $sitePath, string $siteName, string $uri): void
{
// Shortcut for getting the "local" hostname as the HTTP_HOST, especially when proxied or using 'share'
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
}
/**
* Determine if the incoming request is for a static file.
*/
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
{
if (file_exists($staticFilePath = $sitePath.'/public'.$uri)
&& is_file($staticFilePath)) {
return $staticFilePath;
}
$storageUri = $uri;
if (strpos($uri, '/storage/') === 0) {
$storageUri = substr($uri, 8);
}
if ($this->isActualFile($storagePath = $sitePath.'/storage/app/public'.$storageUri)) {
return $storagePath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
return $sitePath.'/public/index.php';
}
}