From 71c6f96f2aab98762c55d1f3000f735ceebd05b4 Mon Sep 17 00:00:00 2001 From: anfu Date: Sat, 14 Sep 2024 10:53:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=8D=E5=90=91=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E8=B0=83=E7=94=A8=E4=BC=9A=E4=BD=BF=E7=94=A8=E6=9A=B4?= =?UTF-8?q?=E9=9C=B2=E7=AB=AF=E5=8F=A3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- app/controller/Index.php | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 29adf62..ed0e817 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ services: |-|-|-|-| |`NACOS_ADDR`| nacos注册地址 |`192.168.1.105:8848` |*| |`SERVICE_PORT`| 指定外部可以向内访问的端口 |`8000`|*| -|`ORIGIN_URL`| 允许跨域的域名 |docker容器内ip|-| +|`ORIGIN_URL`| 允许跨域的网址 |`{docker容器内ip}:8000`|-| 内部暴露的端口 - diff --git a/app/controller/Index.php b/app/controller/Index.php index 72aafb7..41103a0 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -27,15 +27,10 @@ class Index // thinkphp里面无法获取SERVER_ADDR变量,会被nacos拦截替换 // 服务暴露的端口 $servicePort = $env->get('SERVICE_PORT', 8000); - if ($servicePort == 80) { - $servicePort = ''; - } else { - $servicePort = ':' . $servicePort; - } // 服务可以访问到的IP $serverIP = $env->get('SERVER_ADDR'); // 允许跨域的域名 - $originUrl = $env->get('ORIGIN_URL', $serverIP); + $originUrl = $env->get('ORIGIN_URL', $serverIP . ':' . $servicePort); // 组装保存路径 $savename = \think\facade\Filesystem::disk('upload')->putFile('uploads', $file); @@ -46,7 +41,7 @@ class Index 'msg' => null, 'data' => [ "name" => $trueName, - "url" => '//' . $originUrl . $servicePort . '/' . $savename, + "url" => '//' . $originUrl . '/' . $savename, // "url" => 'http://192.168.1.105:8080/file/' . $savename, ], // 'env' => $env->get(),