Skip to content

Commit dba57d8

Browse files
authored
feat(router): allow specifying port using host:port syntax (#1321)
1 parent d4a219d commit dba57d8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/router/src/Commands/ServeCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Tempest\Router\Commands;
66

77
use Tempest\Console\ConsoleCommand;
8+
use Tempest\Intl\Number;
9+
use Tempest\Support\Str;
810

911
final readonly class ServeCommand
1012
{
@@ -15,6 +17,12 @@
1517
public function __invoke(string $host = 'localhost', int $port = 8000, string $publicDir = 'public/'): void
1618
{
1719
$routerFile = __DIR__ . '/router.php';
20+
21+
if (Str\contains($host, ':')) {
22+
[$host, $overridenPort] = explode(':', $host, limit: 2);
23+
$port = Number\parse($overridenPort, default: $port);
24+
}
25+
1826
passthru("php -S {$host}:{$port} -t {$publicDir} {$routerFile}");
1927
}
2028
}

0 commit comments

Comments
 (0)