Skip to content

Commit 01f4b58

Browse files
♻️ Refactoring proxy command. Proxy is not secured by default.
1 parent 7fdcdd3 commit 01f4b58

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

cli/Valet/Site.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ function unsecureAll()
710710
*
711711
* @param string $url The domain name to serve
712712
* @param string $host The URL to proxy to, eg: http://127.0.0.1:8080
713-
* @param bool $insecure
713+
* @param bool $secure
714714
* @return string
715715
*/
716-
function proxyCreate($url, $host, $insecure = false)
716+
function proxyCreate($url, $host, $secure = false)
717717
{
718718
if (!preg_match('~^https?://.*$~', $host)) {
719719
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL', $host));
@@ -726,7 +726,7 @@ function proxyCreate($url, $host, $insecure = false)
726726

727727
$siteConf = $this->replaceOldLoopbackWithNew(
728728
$this->files->get(
729-
$insecure ? __DIR__.'/../stubs/insecure.proxy.valet.conf' : __DIR__.'/../stubs/secure.proxy.valet.conf'
729+
$secure ? __DIR__.'/../stubs/secure.proxy.valet.conf' : __DIR__.'/../stubs/proxy.valet.conf'
730730
),
731731
'VALET_LOOPBACK',
732732
$this->valetLoopback()
@@ -738,13 +738,13 @@ function proxyCreate($url, $host, $insecure = false)
738738
$siteConf
739739
);
740740

741-
if ($insecure) {
742-
$this->putInsecurely($url, $siteConf);
743-
} else {
741+
if ($secure) {
744742
$this->secure($url, $siteConf);
743+
} else {
744+
$this->put($url, $siteConf);
745745
}
746746

747-
$protocol = $insecure ? 'http' : 'https';
747+
$protocol = $secure ? 'https' : 'http';
748748

749749
info('Valet will now proxy ['.$protocol.'://'.$url.'] traffic to ['.$host.'].');
750750
}
@@ -775,7 +775,7 @@ function proxyDelete($url)
775775
* @param string $siteConf pregenerated Nginx config file contents
776776
* @return void
777777
*/
778-
function putInsecurely($url, $siteConf)
778+
function put($url, $siteConf)
779779
{
780780
$this->unsecure($url);
781781

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# valet stub: insecure.proxy.valet.conf
1+
# valet stub: proxy.valet.conf
22

33
server {
44
listen 127.0.0.1:80;

cli/valet.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@
210210
/**
211211
* Create an Nginx proxy config for the specified domain
212212
*/
213-
$app->command('proxy domain host [--insecure]', function ($domain, $host, $insecure) {
213+
$app->command('proxy domain host [--secure]', function ($domain, $host, $secure) {
214214

215-
Site::proxyCreate($domain, $host, $insecure);
215+
Site::proxyCreate($domain, $host, $secure);
216216
Nginx::restart();
217217

218218
})->descriptions('Create an Nginx proxy site for the specified host. Useful for docker, mailhog etc.', [
219-
'--insecure' => 'Create a proxy without SSL'
219+
'--secure' => 'Create a proxy with a trusted TLS certificate'
220220
]);
221221

222222
/**

tests/SiteTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public function test_add_proxy()
353353
$site->assertCertificateNotExists('my-new-proxy.com.test');
354354
$site->assertNginxNotExists('my-new-proxy.com.test');
355355

356-
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
356+
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
357357

358358
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 0);
359359
$site->assertNginxExists('my-new-proxy.com.test');
@@ -387,7 +387,7 @@ public function test_add_non_secure_proxy()
387387
$site->assertCertificateNotExists('my-new-proxy.com.test');
388388
$site->assertNginxNotExists('my-new-proxy.com.test');
389389

390-
$site->proxyCreate('my-new-proxy.com', 'http://127.0.0.1:9443', true);
390+
$site->proxyCreate('my-new-proxy.com', 'http://127.0.0.1:9443', false);
391391

392392
$site->assertCertificateNotExists('my-new-proxy.com.test');
393393
$site->assertNginxExists('my-new-proxy.com.test');
@@ -418,7 +418,7 @@ public function test_add_proxy_clears_previous_proxy_certificate()
418418

419419
$site->useOutput();
420420

421-
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:7443');
421+
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:7443', true);
422422

423423
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 0);
424424

@@ -432,7 +432,7 @@ public function test_add_proxy_clears_previous_proxy_certificate()
432432
], $site->proxies()->all());
433433

434434
// Note: different proxy port
435-
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
435+
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
436436

437437
// This shows we created a new certificate.
438438
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 1);
@@ -470,7 +470,7 @@ public function test_add_proxy_clears_previous_non_proxy_certificate()
470470
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 0);
471471
$site->assertNginxNotExists('my-new-proxy.com.test');
472472

473-
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
473+
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
474474

475475
// This shows we created a new certificate.
476476
$site->assertCertificateExistsWithCounterValue('my-new-proxy.com.test', 1);
@@ -507,7 +507,7 @@ public function test_remove_proxy()
507507

508508
$this->assertEquals([], $site->proxies()->all());
509509

510-
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443');
510+
$site->proxyCreate('my-new-proxy.com', 'https://127.0.0.1:9443', true);
511511

512512
$this->assertEquals([
513513
'my-new-proxy.com' => [

0 commit comments

Comments
 (0)