增加局域网内部自签名使用方式
This commit is contained in:
+7
-1
@@ -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
|
||||
# End of https://www.toptal.com/developers/gitignore/api/go,goland
|
||||
|
||||
|
||||
|
||||
./ncmdump-web
|
||||
|
||||
web/package-lock.json
|
||||
Generated
+3
-1
@@ -2,7 +2,9 @@
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<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="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
## 命令行
|
||||
|
||||
+12
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user