1
0
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:
Taylor Otwell
2016-05-06 10:03:57 -05:00
parent 6b200d1667
commit c651f2cbc4
5 changed files with 70 additions and 4 deletions

View File

@@ -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.
*/

View File

@@ -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.
*

View File

@@ -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
View File

@@ -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

View File

@@ -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.
*/