mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-17 23:45:55 +00:00
Allow specifying local config files when starting the server
This commit is contained in:
@@ -3,20 +3,35 @@
|
|||||||
namespace App\Commands;
|
namespace App\Commands;
|
||||||
|
|
||||||
use App\Server\Factory;
|
use App\Server\Factory;
|
||||||
|
use InvalidArgumentException;
|
||||||
use LaravelZero\Framework\Commands\Command;
|
use LaravelZero\Framework\Commands\Command;
|
||||||
use React\EventLoop\LoopInterface;
|
use React\EventLoop\LoopInterface;
|
||||||
|
|
||||||
class ServeCommand extends Command
|
class ServeCommand extends Command
|
||||||
{
|
{
|
||||||
protected $signature = 'serve {hostname=localhost} {host=0.0.0.0} {--validateAuthTokens} {--port=8080}';
|
protected $signature = 'serve {hostname=localhost} {host=0.0.0.0} {--validateAuthTokens} {--port=8080} {--config=}';
|
||||||
|
|
||||||
protected $description = 'Start the expose server';
|
protected $description = 'Start the expose server';
|
||||||
|
|
||||||
|
protected function loadConfiguration(string $configFile)
|
||||||
|
{
|
||||||
|
$configFile = realpath($configFile);
|
||||||
|
|
||||||
|
throw_if(! file_exists($configFile), new InvalidArgumentException("Invalid config file {$configFile}"));
|
||||||
|
|
||||||
|
$localConfig = require $configFile;
|
||||||
|
config()->set('expose', $localConfig);
|
||||||
|
}
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
/** @var LoopInterface $loop */
|
/** @var LoopInterface $loop */
|
||||||
$loop = app(LoopInterface::class);
|
$loop = app(LoopInterface::class);
|
||||||
|
|
||||||
|
if ($this->option('config')) {
|
||||||
|
$this->loadConfiguration($this->option('config'));
|
||||||
|
}
|
||||||
|
|
||||||
$loop->futureTick(function () {
|
$loop->futureTick(function () {
|
||||||
$this->info('Expose server running on port '.$this->option('port').'.');
|
$this->info('Expose server running on port '.$this->option('port').'.');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user