增加局域网内部自签名使用方式

This commit is contained in:
Misaki
2026-06-08 22:33:23 +08:00
parent 36660519c1
commit e2b65ac735
4 changed files with 72 additions and 10 deletions
+6
View File
@@ -164,3 +164,9 @@ fabric.properties
.idea/**/azureSettings.xml .idea/**/azureSettings.xml
# End of https://www.toptal.com/developers/gitignore/api/go,goland # End of https://www.toptal.com/developers/gitignore/api/go,goland
./ncmdump-web
web/package-lock.json
+3 -1
View File
@@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" /> <component name="Go" enabled="true" />
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/cmd/server/static/dist" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
+50 -5
View File
@@ -19,19 +19,64 @@
> 要求:Chrome / Edge 浏览器,通过 `localhost` 或 HTTPS 访问。 > 要求: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 部署 ### Docker 部署
```shell ```shell
docker compose up -d --build docker compose up -d --build
# 访问 http://localhost:8080
``` ```
然后浏览器访问 `http://localhost:8080` 如需提取二进制单独部署:
### 本地开发
```shell ```shell
./build-wasm.sh # 编译 WASM + 前端 + 服务器 docker cp $(docker create ncmdump-web):/usr/local/bin/ncmdump-server ./ncmdump-web
./ncmdump-web --port 8080
``` ```
## 命令行 ## 命令行
+10 -1
View File
@@ -18,6 +18,8 @@ var staticFiles embed.FS
func main() { func main() {
port := flag.Int("port", 8080, "server port") 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() flag.Parse()
distFS, err := fs.Sub(staticFiles, "static/dist") distFS, err := fs.Sub(staticFiles, "static/dist")
@@ -48,9 +50,16 @@ func main() {
os.Exit(0) os.Exit(0)
}() }()
log.Printf("ncmdump-web (WASM mode) starting on :%d", *port)
addr := fmt.Sprintf(":%d", *port) addr := fmt.Sprintf(":%d", *port)
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 { if err := http.ListenAndServe(addr, mux); err != nil {
log.Fatalf("server error: %v", err) log.Fatalf("server error: %v", err)
} }
} }
}