From e2b65ac735681aefc93ac60602e55c1a3276a382 Mon Sep 17 00:00:00 2001 From: Misaki Date: Mon, 8 Jun 2026 22:33:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B1=80=E5=9F=9F=E7=BD=91?= =?UTF-8?q?=E5=86=85=E9=83=A8=E8=87=AA=E7=AD=BE=E5=90=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 ++++++- .idea/ncmdump-go.iml | 4 +++- README.md | 55 ++++++++++++++++++++++++++++++++++++++++---- cmd/server/main.go | 15 +++++++++--- 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index f3b9fb8..fac9afd 100644 --- a/.gitignore +++ b/.gitignore @@ -163,4 +163,10 @@ fabric.properties # https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij .idea/**/azureSettings.xml -# End of https://www.toptal.com/developers/gitignore/api/go,goland \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/go,goland + + + +./ncmdump-web + +web/package-lock.json \ No newline at end of file diff --git a/.idea/ncmdump-go.iml b/.idea/ncmdump-go.iml index 5e764c4..e41d164 100644 --- a/.idea/ncmdump-go.iml +++ b/.idea/ncmdump-go.iml @@ -2,7 +2,9 @@ - + + + diff --git a/README.md b/README.md index c550df1..842e0be 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,64 @@ > 要求:Chrome / Edge 浏览器,通过 `localhost` 或 HTTPS 访问。 +### 直接运行 + +从 [Releases](https://git.taurusxin.com/taurusxin/ncmdump-go/releases/latest) 下载对应平台的 `ncmdump-web` 二进制,或自行编译: + +```shell +./build-wasm.sh + +# 单机使用 +./ncmdump-web --port 8080 +# 浏览器访问 http://localhost:8080 +``` + +### 局域网使用 + +非 `localhost` 下浏览器要求 HTTPS 才能启用文件夹选择功能。用 [mkcert](https://github.com/FiloSottile/mkcert) 生成自签名证书: + +```shell +# 在运行服务器的机器上,替换为实际 IP +mkcert -install +mkcert 192.168.1.100 localhost + +# 启动 +./ncmdump-web --port 8080 --cert 192.168.1.100+1.pem --key 192.168.1.100+1-key.pem +``` + +然后局域网内其他设备访问 `https://192.168.1.100:8080` 即可正常使用。 + +### 交叉编译 + +纯 Go,无 CGO 依赖,可交叉编译到任意平台: + +```shell +# Windows +CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o ncmdump-web.exe ./cmd/server + +# macOS (Intel) +CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o ncmdump-web ./cmd/server + +# macOS (Apple Silicon) +CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o ncmdump-web ./cmd/server + +# Linux (arm64) +CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o ncmdump-web ./cmd/server +``` + +编译出的二进制约 15MB,前端和 WASM 运行时全部内嵌,拷贝到目标机器直接运行。 + ### Docker 部署 ```shell docker compose up -d --build +# 访问 http://localhost:8080 ``` -然后浏览器访问 `http://localhost:8080`。 - -### 本地开发 +如需提取二进制单独部署: ```shell -./build-wasm.sh # 编译 WASM + 前端 + 服务器 -./ncmdump-web --port 8080 +docker cp $(docker create ncmdump-web):/usr/local/bin/ncmdump-server ./ncmdump-web ``` ## 命令行 diff --git a/cmd/server/main.go b/cmd/server/main.go index 4056d74..e302e28 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -18,6 +18,8 @@ var staticFiles embed.FS func main() { port := flag.Int("port", 8080, "server port") + certFile := flag.String("cert", "", "TLS certificate file (enables HTTPS)") + keyFile := flag.String("key", "", "TLS key file (enables HTTPS)") flag.Parse() distFS, err := fs.Sub(staticFiles, "static/dist") @@ -48,9 +50,16 @@ func main() { os.Exit(0) }() - log.Printf("ncmdump-web (WASM mode) starting on :%d", *port) addr := fmt.Sprintf(":%d", *port) - if err := http.ListenAndServe(addr, mux); err != nil { - log.Fatalf("server error: %v", err) + if *certFile != "" && *keyFile != "" { + log.Printf("ncmdump-web (WASM mode) starting on https://localhost:%d", *port) + if err := http.ListenAndServeTLS(addr, *certFile, *keyFile, mux); err != nil { + log.Fatalf("server error: %v", err) + } + } else { + log.Printf("ncmdump-web (WASM mode) starting on http://localhost:%d", *port) + if err := http.ListenAndServe(addr, mux); err != nil { + log.Fatalf("server error: %v", err) + } } }