1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00

Add set-ngrok-token command

This commit is contained in:
Matt Stauffer
2022-12-22 10:30:50 -05:00
parent 72212fb7b6
commit b200022041
3 changed files with 27 additions and 2 deletions

View File

@@ -8,11 +8,17 @@
class Ngrok
{
public $cli;
public $tunnelsEndpoints = [
'http://127.0.0.1:4040/api/tunnels',
'http://127.0.0.1:4041/api/tunnels',
];
public function __construct(CommandLine $cli)
{
$this->cli = $cli;
}
/**
* Get the current tunnel URL from the Ngrok API.
*
@@ -65,4 +71,15 @@ public function findHttpTunnelUrl($tunnels, $domain)
}
}
}
/**
* Set the Ngrok auth token.
*
* @param string $token
* @return string
*/
public function setToken($token)
{
return $this->cli->runAsUser('./bin/ngrok authtoken '.$token);
}
}

View File

@@ -321,6 +321,13 @@ function (ConsoleCommandEvent $event) {
output(Ngrok::currentTunnelUrl(Site::domain($domain)));
})->descriptions('Get the URL to the current Ngrok tunnel');
/**
* Set the ngrok auth token.
*/
$app->command('set-ngrok-token [token]', function (OutputInterface $output, $token = null) {
output(Ngrok::setToken($token));
})->descriptions('Set the Ngrok auth token');
/**
* Start the daemon services.
*/

View File

@@ -1,6 +1,7 @@
<?php
use Illuminate\Container\Container;
use Valet\CommandLine;
use Valet\Ngrok;
use function Valet\user;
@@ -47,7 +48,7 @@ public function test_it_matches_correct_share_tunnel()
],
];
$ngrok = new Ngrok;
$ngrok = new Ngrok(new CommandLine);
$this->assertEquals('http://right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'mysite'));
}
@@ -63,7 +64,7 @@ public function test_it_checks_against_lowercased_domain()
],
];
$ngrok = new Ngrok;
$ngrok = new Ngrok(new CommandLine);
$this->assertEquals('http://right-one.ngrok.io/', $ngrok->findHttpTunnelUrl($tunnels, 'MySite'));
}
}