From a5a6ea4a93305a7c42e1317fbde69278b02ac336 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Wed, 23 Sep 2026 02:46:44 +0800 Subject: [PATCH] =?UTF-8?q?chore(frp):=20=E6=96=B0=E5=A2=9E=20frpc=20?= =?UTF-8?q?=E9=9A=A7=E9=81=93=E5=AE=89=E8=A3=85/=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=B8=8E=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E6=9C=AC=E5=9C=B0=20frpc.exe=20=E4=BA=8C=E8=BF=9B?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ frpc.toml | 17 +++++++++++++++ package.json | 2 ++ script/frp/frp-install.ps1 | 42 ++++++++++++++++++++++++++++++++++++++ script/frp/frp-start.ps1 | 18 ++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 frpc.toml create mode 100644 script/frp/frp-install.ps1 create mode 100644 script/frp/frp-start.ps1 diff --git a/.gitignore b/.gitignore index 9a0fa2c..996ebe6 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ script/debug-*.cjs .ssl/ nginx_config/ nginx-upstream-local.conf + +# frpc binary (installed on demand by script/frp/frp-install.ps1) +script/frp/*.exe diff --git a/frpc.toml b/frpc.toml new file mode 100644 index 0000000..4d3c28b --- /dev/null +++ b/frpc.toml @@ -0,0 +1,17 @@ +# frpc 客户端配置(frp v0.70.1,复用本机 printServer 的 frpc.exe;生产 frps 为 v0.61.1) +# 用途:将本地 WMS 开发服务(http://127.0.0.1:6060)通过生产环境 frps +# 暴露为 http://test.wms.o.gztbyc.com(frps subDomainHost=o.gztbyc.com)。 +# 启动:npm run frpc:start(首次自动从 D:\printServer 复制 frpc.exe 到 script/frp/) + +serverAddr = "112.124.21.102" +serverPort = 6005 +auth.token = "frpPrintToken2024" + +# 测试域名:test_wms.o.gztbyc.com +# (subdomain + 生产 frps 的 subDomainHost 泛域名拼接,经 vhostHTTPPort 18080 对外) +[[proxies]] +name = "wms-test" +type = "http" +localIP = "127.0.0.1" +localPort = 6060 +subdomain = "test_wms" diff --git a/package.json b/package.json index 933df6d..0cd9775 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,8 @@ "start": "egg-scripts start ", "stop": "node ./app/lib/stop_current_egg.js", "dev": "egg-bin dev --port=6060", + "frpc:install": "powershell -ExecutionPolicy Bypass -File ./script/frp/frp-install.ps1", + "frpc:start": "powershell -ExecutionPolicy Bypass -File ./script/frp/frp-start.ps1", "file-writer:pressure": "node ./temp/generated-tests/file-writer-pressure.generated.test.cjs", "debug:webhook:receiver": "node ./script/debug-webhook-receiver.cjs", "debug:webhook:receiving": "node ./script/debug-send-receiving-webhooks.cjs", diff --git a/script/frp/frp-install.ps1 b/script/frp/frp-install.ps1 new file mode 100644 index 0000000..3a243d2 --- /dev/null +++ b/script/frp/frp-install.ps1 @@ -0,0 +1,42 @@ +# Put frpc.exe into script/frp/ (same dir as this script). +# Priority: 1) reuse local D:\printServer\frpc\frpc.exe 2) download from GitHub. +# ASCII only, avoids ANSI encoding issues with Chinese paths. +$ErrorActionPreference = 'Stop' + +$FrpDir = $PSScriptRoot +$Exe = Join-Path $FrpDir 'frpc.exe' + +if (Test-Path $Exe) { + Write-Output "frpc.exe already exists: $Exe" + exit 0 +} + +New-Item -ItemType Directory -Force -Path $FrpDir | Out-Null + +# 1) reuse frpc from local printServer project +$LocalFrpc = 'D:\printServer\frpc\frpc.exe' +if (Test-Path $LocalFrpc) { + Copy-Item -Force $LocalFrpc $Exe + Write-Output "frpc.exe copied from $LocalFrpc -> $Exe" + exit 0 +} + +# 2) download (fallback) +$Version = '0.61.1' +$ZipName = "frp_${Version}_windows_amd64.zip" +$Url = "https://github.com/fatedier/frp/releases/download/v$Version/$ZipName" +$TmpZip = Join-Path $FrpDir $ZipName +$ExtractDir = Join-Path $FrpDir "frp_${Version}_windows_amd64" + +Write-Output "Downloading $Url ..." +Invoke-WebRequest -Uri $Url -OutFile $TmpZip -UseBasicParsing + +Write-Output "Extracting ..." +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory($TmpZip, $FrpDir) + +Move-Item -Force (Join-Path $ExtractDir 'frpc.exe') $Exe +Remove-Item -Recurse -Force $ExtractDir +Remove-Item -Force $TmpZip + +Write-Output "frpc.exe installed: $Exe" diff --git a/script/frp/frp-start.ps1 b/script/frp/frp-start.ps1 new file mode 100644 index 0000000..46f15d8 --- /dev/null +++ b/script/frp/frp-start.ps1 @@ -0,0 +1,18 @@ +# Start frpc with the project frpc.toml (copy frpc.exe first if missing). +# ASCII only, avoids ANSI encoding issues with Chinese paths. +$ErrorActionPreference = 'Stop' + +$FrpDir = $PSScriptRoot +$Exe = Join-Path $FrpDir 'frpc.exe' + +if (-not (Test-Path $Exe)) { + Write-Output 'frpc.exe not found, installing ...' + & (Join-Path $PSScriptRoot 'frp-install.ps1') +} + +$ProjectRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) +$Config = Join-Path $ProjectRoot 'frpc.toml' +$Config = (Resolve-Path $Config).Path + +Write-Output "Starting frpc with config: $Config" +& $Exe -c $Config