Skip to content

Commit 452d13b

Browse files
authored
Merge pull request #1039 from mikaelpopowicz/loopback
Add loopback command
2 parents 323a239 + 3ecf64d commit 452d13b

File tree

14 files changed

+314
-32
lines changed

14 files changed

+314
-32
lines changed

cli/Valet/Configuration.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function install()
3636

3737
/**
3838
* Forcefully delete the Valet home configuration directory and contents.
39-
*
39+
*
4040
* @return void
4141
*/
4242
function uninstall()
@@ -130,19 +130,21 @@ function createCertificatesDirectory()
130130
function writeBaseConfiguration()
131131
{
132132
if (! $this->files->exists($this->path())) {
133-
$this->write(['tld' => 'test', 'paths' => []]);
133+
$this->write(['tld' => 'test', 'loopback' => VALET_LOOPBACK, 'paths' => []]);
134134
}
135135

136136
/**
137137
* Migrate old configurations from 'domain' to 'tld'
138138
*/
139139
$config = $this->read();
140140

141-
if (isset($config['tld'])) {
142-
return;
141+
if (! isset($config['tld'])) {
142+
$this->updateKey('tld', !empty($config['domain']) ? $config['domain'] : 'test');
143143
}
144144

145-
$this->updateKey('tld', !empty($config['domain']) ? $config['domain'] : 'test');
145+
if (! isset($config['loopback'])) {
146+
$this->updateKey('loopback', VALET_LOOPBACK);
147+
}
146148
}
147149

148150
/**

cli/Valet/Diagnose.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ class Diagnose
4141
'ls -al ~/Library/LaunchAgents | grep homebrew',
4242
'ls -al /Library/LaunchAgents | grep homebrew',
4343
'ls -al /Library/LaunchDaemons | grep homebrew',
44+
'ls -al /Library/LaunchDaemons | grep "com.laravel.valet."',
4445
'ls -aln /etc/resolv.conf',
4546
'cat /etc/resolv.conf',
47+
'ifconfig lo0',
48+
'sh -c \'echo "------\n'.BREW_PREFIX.'/etc/nginx/valet/valet.conf\n---\n"; cat '.BREW_PREFIX.'/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"\'',
49+
'sh -c \'for file in ~/.config/valet/dnsmasq.d/*; do echo "------\n~/.config/valet/dnsmasq.d/$(basename $file)\n---\n"; cat $file; echo "\n------\n"; done\'',
50+
'sh -c \'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done\'',
4651
];
4752

4853
var $cli, $files, $print, $progressBar;

cli/Valet/DnsMasq.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function install($tld = 'test')
4646

4747
/**
4848
* Forcefully uninstall dnsmasq.
49-
*
49+
*
5050
* @return void
5151
*/
5252
function uninstall()
@@ -60,7 +60,7 @@ function uninstall()
6060

6161
/**
6262
* Tell Homebrew to restart dnsmasq
63-
*
63+
*
6464
* @return void
6565
*/
6666
function restart()
@@ -113,21 +113,23 @@ function ensureUsingDnsmasqDForConfigs()
113113
function createDnsmasqTldConfigFile($tld)
114114
{
115115
$tldConfigFile = $this->dnsmasqUserConfigDir() . 'tld-' . $tld . '.conf';
116+
$loopback = $this->configuration->read()['loopback'];
116117

117-
$this->files->putAsUser($tldConfigFile, 'address=/.'.$tld.'/127.0.0.1'.PHP_EOL.'listen-address=127.0.0.1'.PHP_EOL);
118+
$this->files->putAsUser($tldConfigFile, 'address=/.'.$tld.'/'.$loopback.PHP_EOL.'listen-address='.$loopback.PHP_EOL);
118119
}
119120

120121
/**
121-
* Create the resolver file to point the configured TLD to 127.0.0.1.
122+
* Create the resolver file to point the configured TLD to configured loopback address.
122123
*
123124
* @param string $tld
124125
* @return void
125126
*/
126127
function createTldResolver($tld)
127128
{
128129
$this->files->ensureDirExists($this->resolverPath);
130+
$loopback = $this->configuration->read()['loopback'];
129131

130-
$this->files->put($this->resolverPath.'/'.$tld, 'nameserver 127.0.0.1'.PHP_EOL);
132+
$this->files->put($this->resolverPath.'/'.$tld, 'nameserver '.$loopback.PHP_EOL);
131133
}
132134

133135
/**
@@ -145,6 +147,18 @@ function updateTld($oldTld, $newTld)
145147
$this->install($newTld);
146148
}
147149

150+
/**
151+
* Refresh the DnsMasq configuration.
152+
*
153+
* @return void
154+
*/
155+
function refreshConfiguration()
156+
{
157+
$tld = $this->configuration->read()['tld'];
158+
159+
$this->updateTld($tld, $tld);
160+
}
161+
148162
/**
149163
* Get the custom configuration path.
150164
*

cli/Valet/Nginx.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function installServer()
8080
str_replace(
8181
['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'],
8282
[VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX],
83-
$this->files->get(__DIR__.'/../stubs/valet.conf')
83+
$this->replaceLoopback($this->files->get(__DIR__.'/../stubs/valet.conf'))
8484
)
8585
);
8686

@@ -90,6 +90,23 @@ function installServer()
9090
);
9191
}
9292

93+
function replaceLoopback($siteConf)
94+
{
95+
$loopback = $this->configuration->read()['loopback'];
96+
97+
if ($loopback === VALET_LOOPBACK) {
98+
return $siteConf;
99+
}
100+
101+
$str = '#listen VALET_LOOPBACK:80; # valet loopback';
102+
103+
return str_replace(
104+
$str,
105+
substr(str_replace('VALET_LOOPBACK', $loopback, $str), 1),
106+
$siteConf
107+
);
108+
}
109+
93110
/**
94111
* Install the Nginx configuration directory to the ~/.config/valet directory.
95112
*
@@ -131,8 +148,15 @@ function ($exitCode, $outputMessage) {
131148
function rewriteSecureNginxFiles()
132149
{
133150
$tld = $this->configuration->read()['tld'];
151+
$loopback = $this->configuration->read()['loopback'];
152+
153+
if ($loopback !== VALET_LOOPBACK) {
154+
$this->site->aliasLoopback(VALET_LOOPBACK, $loopback);
155+
}
156+
157+
$config = compact('tld', 'loopback');
134158

135-
$this->site->resecureForNewTld($tld, $tld);
159+
$this->site->resecureForNewConfiguration($config, $config);
136160
}
137161

138162
/**

0 commit comments

Comments
 (0)