Skip to content

Commit 21c6855

Browse files
authored
Merge pull request #1133 from hydephp/refactor-the-serve-command
Add configuration option for the realtime compiler server host
2 parents f44c532 + 78c5ac0 commit 21c6855

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ SITE_URL=http://localhost
44
# If you want to use Torchlight.dev, enter your API token here to automatically enable it.
55
# TORCHLIGHT_TOKEN=torch_
66

7-
# If you want to change the default port of the realtime compiler server, you can do so here
7+
# If you want to change the default port or host of the realtime compiler server, you can do so here
88
# SERVER_PORT=8080
9+
# SERVER_HOST=localhost

config/hyde.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156

157157
'server' => [
158158
'port' => env('SERVER_PORT', 8080),
159+
'host' => env('SERVER_HOST', 'localhost'),
159160
'dashboard' => env('SERVER_DASHBOARD', true),
160161
],
161162

packages/framework/config/hyde.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156

157157
'server' => [
158158
'port' => env('SERVER_PORT', 8080),
159+
'host' => env('SERVER_HOST', 'localhost'),
159160
'dashboard' => env('SERVER_DASHBOARD', true),
160161
],
161162

packages/framework/src/Console/Commands/ServeCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class ServeCommand extends Command
1919
{
2020
/** @var string */
21-
protected $signature = 'serve {--host=localhost} {--port= : <comment> [default: 8080] </comment>}';
21+
protected $signature = 'serve {--host= : <comment>[default: "localhost"]</comment>}} {--port= : <comment>[default: 8080]</comment>}';
2222

2323
/** @var string */
2424
protected $description = 'Start the realtime compiler server.';
@@ -28,7 +28,7 @@ public function handle(): int
2828
$this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop');
2929

3030
$this->runServerProcess(sprintf('php -S %s:%d %s',
31-
$this->option('host'),
31+
$this->getHostSelection() ?: 'localhost',
3232
$this->getPortSelection() ?: 8080,
3333
$this->getExecutablePath()
3434
));
@@ -41,6 +41,11 @@ protected function getPortSelection(): int
4141
return (int) ($this->option('port') ?: config('hyde.server.port', 8080));
4242
}
4343

44+
protected function getHostSelection(): string
45+
{
46+
return $this->option('host') ?: config('hyde.server.host', 'localhost');
47+
}
48+
4449
protected function getExecutablePath(): string
4550
{
4651
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');

packages/framework/tests/Feature/Commands/ServeCommandTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,39 @@ public function test_hyde_serve_command_with_port_missing_in_config_and_port_opt
8989
Process::assertRan("php -S localhost:8081 {$this->binaryPath()}");
9090
}
9191

92+
public function test_hyde_serve_command_with_host_defined_in_config()
93+
{
94+
config(['hyde.server.host' => 'foo']);
95+
96+
$this->artisan('serve')
97+
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
98+
->assertExitCode(0);
99+
100+
Process::assertRan("php -S foo:8080 {$this->binaryPath()}");
101+
}
102+
103+
public function test_hyde_serve_command_with_host_defined_in_config_and_host_option()
104+
{
105+
config(['hyde.server.host' => 'foo']);
106+
107+
$this->artisan('serve --host=bar')
108+
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
109+
->assertExitCode(0);
110+
111+
Process::assertRan("php -S bar:8080 {$this->binaryPath()}");
112+
}
113+
114+
public function test_hyde_serve_command_with_host_missing_in_config_and_host_option()
115+
{
116+
config(['hyde.server.host' => null]);
117+
118+
$this->artisan('serve --host=foo')
119+
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
120+
->assertExitCode(0);
121+
122+
Process::assertRan("php -S foo:8080 {$this->binaryPath()}");
123+
}
124+
92125
public function test_hyde_serve_command_with_invalid_config_value()
93126
{
94127
config(['hyde.server.port' => 'foo']);

0 commit comments

Comments
 (0)