mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 00:20:08 +01:00
allow updating domain dynamically
This commit is contained in:
@@ -39,6 +39,10 @@ function show_valet_404()
|
||||
'.'.$valetConfig['domain']
|
||||
);
|
||||
|
||||
if (strpos($siteName, 'www.') === 0) {
|
||||
$siteName = substr($siteName, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the fully qualified path to the site.
|
||||
*/
|
||||
|
||||
@@ -113,6 +113,24 @@ public static function read()
|
||||
return json_decode(file_get_contents(static::path()), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific key in the configuration file.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function updateKey($key, $value)
|
||||
{
|
||||
$config = static::read();
|
||||
|
||||
$config[$key] = $value;
|
||||
|
||||
static::write($config);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the given configuration to disk.
|
||||
*
|
||||
|
||||
@@ -103,4 +103,22 @@ protected static function createResolver()
|
||||
|
||||
file_put_contents('/etc/resolver/dev', 'nameserver 127.0.0.1'.PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the domain used by DnsMasq.
|
||||
*
|
||||
* @param string $oldDomain
|
||||
* @param string $newDomain
|
||||
* @return void
|
||||
*/
|
||||
public static function updateDomain($oldDomain, $newDomain)
|
||||
{
|
||||
quietly('rm /etc/resolver/'.$oldDomain);
|
||||
|
||||
file_put_contents('/etc/resolver/'.$newDomain, 'nameserver 127.0.0.1'.PHP_EOL);
|
||||
|
||||
file_put_contents(VALET_HOME_PATH.'/dnsmasq.conf', 'address=/.'.$newDomain.'/127.0.0.1'.PHP_EOL);
|
||||
|
||||
passthru('sudo brew services restart dnsmasq');
|
||||
}
|
||||
}
|
||||
|
||||
8
valet
8
valet
@@ -10,12 +10,14 @@ then
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
|
||||
if [[ "$1" = "install" ]] || [[ "$1" = "start" ]] || [[ "$1" = "restart" ]] || [[ "$1" = "stop" ]] || [[ "$1" = "uninstall" ]]
|
||||
if [[ "$1" = "install" ]] || [[ "$1" = "domain" ]] || [[ "$1" = "start" ]] || [[ "$1" = "restart" ]] || [[ "$1" = "stop" ]] || [[ "$1" = "uninstall" ]]
|
||||
then
|
||||
sudo php "$DIR/valet.php" "$@"
|
||||
elif [[ "$1" = "share" ]]
|
||||
then
|
||||
HOST="${PWD##*/}"
|
||||
DOMAIN=$(php "$DIR/valet.php" current-domain)
|
||||
|
||||
|
||||
for linkname in ~/.valet/Sites/*; do
|
||||
RESOLVED_LINK="$(readlink $linkname)"
|
||||
@@ -26,8 +28,10 @@ then
|
||||
fi
|
||||
done
|
||||
|
||||
# Fetch Ngrok URL In Background...
|
||||
bash "$DIR/fetch-share-url.sh" &
|
||||
"$DIR/bin/ngrok" http -host-header=rewrite "$HOST.dev:80"
|
||||
|
||||
"$DIR/bin/ngrok" http -host-header=rewrite "$HOST.$DOMAIN:80"
|
||||
else
|
||||
php "$DIR/valet.php" $@
|
||||
fi
|
||||
22
valet.php
22
valet.php
@@ -43,6 +43,28 @@
|
||||
$output->writeln(PHP_EOL.'<info>Valet installed successfully!</info>');
|
||||
});
|
||||
|
||||
/**
|
||||
* Change the domain currently being used by Valet.
|
||||
*/
|
||||
$app->command('domain domain', function ($domain, $output) {
|
||||
should_be_sudo();
|
||||
|
||||
$domain = trim($domain, '.');
|
||||
|
||||
Valet\DnsMasq::updateDomain(Valet\Configuration::read()['domain'], $domain);
|
||||
|
||||
Valet\Configuration::updateKey('domain', $domain);
|
||||
|
||||
$output->writeln('<info>Your Valet domain has been updated to ['.$domain.'].</info>');
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the domain currently being used by Valet.
|
||||
*/
|
||||
$app->command('current-domain', function ($output) {
|
||||
$output->writeln(Valet\Configuration::read()['domain']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Add the current working directory to the paths configuration.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user