Skip to content

Commit

Permalink
Remove public path -> document root change
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarip committed Jan 12, 2021
1 parent 428e5d1 commit 96a93e9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/swoole_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'server' => [
'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'),
'port' => env('SWOOLE_HTTP_PORT', '1215'),
'document_root' => base_path('public'),
'public_path' => base_path('public'),
// Determine if to use swoole to respond request for static files
'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true),
'access_log' => env('SWOOLE_HTTP_ACCESS_LOG', false),
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ public function onRequest($swooleRequest, $swooleResponse)
$this->resetOnRequest();
$sandbox = $this->app->make(Sandbox::class);
$handleStatic = $this->container->make('config')->get('swoole_http.server.handle_static_files', true);
$documentRoot = $this->container->make('config')->get('swoole_http.server.document_root', base_path('public'));
$publicPath = $this->container->make('config')->get('swoole_http.server.public_path', base_path('public'));

try {
// handle static file request first
if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $documentRoot)) {
if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $publicPath)) {
return;
}
// transform swoole request to illuminate request
Expand Down
8 changes: 4 additions & 4 deletions src/Transformers/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ protected static function transformServerParameters(array $server, array $header
*
* @param \Swoole\Http\Request $swooleRequest
* @param \Swoole\Http\Response $swooleResponse
* @param string $documentRoot
* @param string $publicPath
*
* @return boolean
*/
public static function handleStatic($swooleRequest, $swooleResponse, string $documentRoot)
public static function handleStatic($swooleRequest, $swooleResponse, string $publicPath)
{
$uri = $swooleRequest->server['request_uri'] ?? '';
$extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?');
$fileName = @realpath($documentRoot . $uri);
$fileName = @realpath($publicPath . $uri);

if (!$fileName) {
return false;
Expand All @@ -193,7 +193,7 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $doc
return false;
}

if (substr($fileName, 0, strlen($documentRoot)) != $documentRoot) {
if (substr($fileName, 0, strlen($publicPath)) != $publicPath) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Server/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ManagerTest extends TestCase
'swoole_http.tables' => [],
'swoole_http.providers' => [],
'swoole_http.resetters' => [],
'swoole_http.server.document_root' => '/',
'swoole_http.server.public_path' => '/',
];

public function testGetFramework()
Expand Down

0 comments on commit 96a93e9

Please sign in to comment.