Skip to content

Commit db277db

Browse files
committed
* HTTP默认索引页
1 parent f82aec4 commit db277db

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/HttpServer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function onRequest($request, $response)
155155

156156
do {
157157
if ($this->route->getPath() == '') {
158-
$indexFile = $this->config['http']['domain'][$this->route->getHost()]['index'] ?? __DIR__ . '/Views/index.html';
158+
$indexFile = $this->config['http']['domain'][$this->route->getHost()]['index'] ?? null;
159159
$response->header('X-Ngx-LogId', $PGLog->logId);
160160
$httpCode = $this->sendFile($indexFile, $request, $response);
161161
$PGLog->pushLog('http-code', $httpCode);
@@ -362,6 +362,17 @@ public function genLogId($request)
362362
*/
363363
public function sendFile($path, $request, $response)
364364
{
365+
if (empty($path)) {
366+
$path = __DIR__ . '/Views/index.html';
367+
if (!$response->sendfile($path)) {
368+
swoole_async_readfile($path, function ($filename, $content) use ($response) {
369+
$response->end($content);
370+
});
371+
}
372+
373+
return Marco::SEND_FILE_200;
374+
}
375+
365376
$path = realpath(urldecode($path));
366377
$root = $this->config['http']['domain'][$this->route->getHost()]['root'] ?? null;
367378

0 commit comments

Comments
 (0)