From 7fadb687cc90bfe09fb750d0504be51810374d1a Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Fri, 4 Mar 2022 12:21:44 +0100 Subject: [PATCH] Allow specifying local config files when starting the server --- app/Commands/ServeCommand.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Commands/ServeCommand.php b/app/Commands/ServeCommand.php index 1b7c1d4..a98ba20 100644 --- a/app/Commands/ServeCommand.php +++ b/app/Commands/ServeCommand.php @@ -3,20 +3,35 @@ namespace App\Commands; use App\Server\Factory; +use InvalidArgumentException; use LaravelZero\Framework\Commands\Command; use React\EventLoop\LoopInterface; 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 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() { /** @var LoopInterface $loop */ $loop = app(LoopInterface::class); + if ($this->option('config')) { + $this->loadConfiguration($this->option('config')); + } + $loop->futureTick(function () { $this->info('Expose server running on port '.$this->option('port').'.'); });