chore: support configurable api port
This commit is contained in:
@@ -125,7 +125,10 @@ class MaterialLocalResourceService
|
||||
}
|
||||
|
||||
if (!in_array(strtolower((string)($_ENV['APP_ENV'] ?? '')), ['production', 'prod'], true)) {
|
||||
return 'http://' . '127.0.0.' . '1:8787';
|
||||
$port = filter_var($_ENV['APP_PORT'] ?? '', FILTER_VALIDATE_INT, [
|
||||
'options' => ['min_range' => 1, 'max_range' => 65535],
|
||||
]) ?: 8787;
|
||||
return 'http://' . '127.0.0.' . '1:' . $port;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
@@ -18,10 +18,34 @@ use app\process\Http;
|
||||
|
||||
global $argv;
|
||||
|
||||
$resolveServerPort = static function (): int {
|
||||
$rawPort = $_ENV['APP_PORT'] ?? $_SERVER['APP_PORT'] ?? getenv('APP_PORT') ?: '';
|
||||
if ($rawPort === '' && is_file(base_path('.env'))) {
|
||||
foreach (file(base_path('.env'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [] as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || str_starts_with($line, '#') || !str_contains($line, '=')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$key, $value] = array_map('trim', explode('=', $line, 2));
|
||||
if ($key === 'APP_PORT') {
|
||||
$rawPort = trim($value, "\"'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$port = filter_var($rawPort, FILTER_VALIDATE_INT, [
|
||||
'options' => ['min_range' => 1, 'max_range' => 65535],
|
||||
]);
|
||||
|
||||
return $port ?: 8787;
|
||||
};
|
||||
|
||||
return [
|
||||
'webman' => [
|
||||
'handler' => Http::class,
|
||||
'listen' => 'http://0.0.0.0:8787',
|
||||
'listen' => 'http://0.0.0.0:' . $resolveServerPort(),
|
||||
'count' => cpu_count() * 4,
|
||||
'user' => '',
|
||||
'group' => '',
|
||||
|
||||
Reference in New Issue
Block a user