Skip to content

Commit ebde2c6

Browse files
authored
feat(http): support implicit host in serve command (#1350)
1 parent f912d6a commit ebde2c6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/router/src/Commands/ServeCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
name: 'serve',
1515
description: 'Starts a PHP development server',
1616
)]
17-
public function __invoke(string $host = 'localhost', int $port = 8000, string $publicDir = 'public/'): void
17+
public function __invoke(string $host = '127.0.0.1', int $port = 8000, string $publicDir = 'public/'): void
1818
{
1919
$routerFile = __DIR__ . '/router.php';
2020

2121
if (Str\contains($host, ':')) {
22-
[$host, $overridenPort] = explode(':', $host, limit: 2);
23-
$port = Number\parse($overridenPort, default: $port);
22+
[$host, $overriddenPort] = explode(':', $host, limit: 2);
23+
24+
$host = $host ?: '127.0.0.1';
25+
26+
$port = Number\parse($overriddenPort, default: $port);
2427
}
2528

2629
passthru("php -S {$host}:{$port} -t {$publicDir} {$routerFile}");

0 commit comments

Comments
 (0)