Skip to content

Commit f936a0c

Browse files
committed
Configurable index file
1 parent 12a34a6 commit f936a0c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

packages/dev-server/src/Internal/HttpHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class HttpHandler implements HttpServerInterface
3535

3636
public function __construct(
3737
private FlySystemAdapter $files,
38+
private string $indexFile = 'index.html',
3839
) {
3940
$this->detector = new ExtensionMimeTypeDetector();
4041
}
@@ -54,11 +55,11 @@ public function onOpen(ConnectionInterface $conn, RequestInterface|null $request
5455

5556
// For empty path (root) serve index.html
5657
if ($requestPath === '') {
57-
$requestPath = 'index.html';
58+
$requestPath = $this->indexFile;
5859
}
5960

6061
if ($this->files->isDirectory($requestPath)) {
61-
$requestPath .= '/index.html';
62+
$requestPath .= '/' . $this->indexFile;
6263
}
6364

6465
if ($this->files->has($requestPath)) {

packages/dev-server/src/ServerFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public function createDevServer(
3535
string $host,
3636
string $listen,
3737
int $port,
38+
string $indexFile = 'index.html',
3839
): Server {
39-
$httpHandler = new HttpHandler($files);
40+
$httpHandler = new HttpHandler($files, $indexFile);
4041
$wsServer = new WebSocketHandler($this->logger);
4142

4243
$app = new App($host, $port, $listen);

packages/guides-cli/src/Command/Serve.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9090
return Command::FAILURE;
9191
}
9292

93+
$this->settingsBuilder->overrideWithInput($input);
94+
$settings = $this->settingsBuilder->getSettings();
95+
9396
$files = FlySystemAdapter::createForPath($dir);
9497
$app = $this->serverFactory->createDevServer(
9598
$inputDir,
9699
$files,
97100
$host,
98101
'0.0.0.0',
99102
$port,
103+
$settings->getIndexName(),
100104
);
101105

102106
$app->addListener(
@@ -106,9 +110,6 @@ static function (PostParseDocument $event) use ($app): void {
106110
},
107111
);
108112

109-
$this->settingsBuilder->overrideWithInput($input);
110-
111-
$settings = $this->settingsBuilder->getSettings();
112113
$projectNode = $this->settingsBuilder->createProjectNode();
113114
$sourceFileSystem = FlySystemAdapter::createForPath($settings->getInput());
114115

0 commit comments

Comments
 (0)