Skip to content

Commit

Permalink
Merge pull request #1284 from thinkverse/fix-local-network-sharing
Browse files Browse the repository at this point in the history
Enable local network sharing
  • Loading branch information
mattstauffer authored Feb 1, 2023
2 parents 70b3681 + 7180feb commit 0879fb8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ function valet_default_site_path($config)
file_get_contents(VALET_HOME_PATH.'/config.json'), true
);

/**
* If the HTTP_HOST is an IP address, check the start of the REQUEST_URI for a
* valid hostname, extract and use it as the effective HTTP_HOST in place
* of the IP. It enables the use of Valet in a local network.
*/
if (preg_match('/^([0-9]+\.){3}[0-9]+$/', $_SERVER['HTTP_HOST'])) {
$uri = ltrim($_SERVER['REQUEST_URI'], '/');

if (preg_match('/^[-.0-9a-zA-Z]+\.'.$valetConfig['tld'].'/', $uri, $matches)) {
$host = $matches[0];
$_SERVER['HTTP_HOST'] = $host;
$_SERVER['REQUEST_URI'] = str_replace($host, '', $uri);
}
}

/**
* Parse the URI and site / host for the incoming request.
*/
Expand Down

0 comments on commit 0879fb8

Please sign in to comment.