mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
feat: 优化开发环境配置
This commit is contained in:
parent
a8d2d6f13f
commit
9b2731607b
@ -61,7 +61,7 @@ class IndexController extends InvokeController
|
|||||||
$array = Base::json2array(file_get_contents($hotFile));
|
$array = Base::json2array(file_get_contents($hotFile));
|
||||||
$style = null;
|
$style = null;
|
||||||
$script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . $array['APP_DEV_PORT'] . "/", asset_main("resources/assets/js/app.js"));
|
$script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . $array['APP_DEV_PORT'] . "/", asset_main("resources/assets/js/app.js"));
|
||||||
$proxyUri = env('VSCODE_PROXY_URI');
|
$proxyUri = Base::liveEnv('VSCODE_PROXY_URI');
|
||||||
if (is_string($proxyUri) && preg_match('/^https?:\/\//i', $proxyUri)) {
|
if (is_string($proxyUri) && preg_match('/^https?:\/\//i', $proxyUri)) {
|
||||||
$script = preg_replace('/^(https?:\/\/|\/\/)[^\/]+/', rtrim($proxyUri, '/'), $script, 1);
|
$script = preg_replace('/^(https?:\/\/|\/\/)[^\/]+/', rtrim($proxyUri, '/'), $script, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3073,4 +3073,61 @@ class Base
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实时读取 .env 配置(不受配置缓存影响)
|
||||||
|
* @param string $key 配置键名
|
||||||
|
* @param mixed $default 默认值
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function liveEnv($key, $default = null)
|
||||||
|
{
|
||||||
|
$envFile = base_path('.env');
|
||||||
|
if (!file_exists($envFile)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
$envContent = file_get_contents($envFile);
|
||||||
|
$lines = explode("\n", $envContent);
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$line = trim($line);
|
||||||
|
|
||||||
|
// 跳过注释和空行
|
||||||
|
if (empty($line) || str_starts_with($line, '#')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析 KEY=VALUE
|
||||||
|
if (str_contains($line, '=')) {
|
||||||
|
[$envKey, $envValue] = explode('=', $line, 2);
|
||||||
|
$envKey = trim($envKey);
|
||||||
|
|
||||||
|
if ($envKey === $key) {
|
||||||
|
$envValue = trim($envValue);
|
||||||
|
|
||||||
|
// 移除引号
|
||||||
|
if (preg_match('/^(["\'])(.*)\1$/', $envValue, $matches)) {
|
||||||
|
$envValue = $matches[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理布尔值
|
||||||
|
$lowerValue = strtolower($envValue);
|
||||||
|
if ($lowerValue === 'true') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($lowerValue === 'false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($lowerValue === 'null' || $lowerValue === '(null)') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $envValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
cmd
2
cmd
@ -175,7 +175,7 @@ web_build() {
|
|||||||
fi
|
fi
|
||||||
if [ "$type" = "dev" ]; then
|
if [ "$type" = "dev" ]; then
|
||||||
echo "<script>window.location.href=window.location.href.replace(/:\d+/, ':' + $(env_get APP_PORT))</script>" > ./index.html
|
echo "<script>window.location.href=window.location.href.replace(/:\d+/, ':' + $(env_get APP_PORT))</script>" > ./index.html
|
||||||
if [[ -z "$(env_get APP_DEV_PORT)" ]] || [[ -z "${VSCODE_PROXY_URI:-}" ]]; then
|
if [ -z "$(env_get APP_DEV_PORT)" ]; then
|
||||||
env_set APP_DEV_PORT $(rand 20001 30000)
|
env_set APP_DEV_PORT $(rand 20001 30000)
|
||||||
fi
|
fi
|
||||||
if [ -n "${VSCODE_PROXY_URI:-}" ]; then
|
if [ -n "${VSCODE_PROXY_URI:-}" ]; then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user