From 85eb501a428f14a6c6242f3321c5b4b86a44253e Mon Sep 17 00:00:00 2001 From: wintsa <770775984@qq.com> Date: Thu, 26 Mar 2026 16:43:58 +0800 Subject: [PATCH] 1 --- .dockerignore | 7 + Dockerfile.dist | 18 + docker/dist-server/go.mod | 3 + docker/dist-server/main.go | 69 + index.html | 4 +- public/data.js | 372 ----- public/基础参数及报表导出功能.js | 1918 -------------------------- public/标准文件转代码Data.xlsx | Bin 122254 -> 0 bytes public/造价咨询服务计费报表模板.xlsx | Bin 42648 -> 0 bytes scripts/package-dist-image.ps1 | 45 + tsconfig.tsbuildinfo | 2 +- 11 files changed, 145 insertions(+), 2293 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile.dist create mode 100644 docker/dist-server/go.mod create mode 100644 docker/dist-server/main.go delete mode 100644 public/data.js delete mode 100644 public/基础参数及报表导出功能.js delete mode 100644 public/标准文件转代码Data.xlsx delete mode 100644 public/造价咨询服务计费报表模板.xlsx create mode 100644 scripts/package-dist-image.ps1 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..22909d0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +** +!dist/ +!dist/** +!Dockerfile.dist +!docker/ +!docker/dist-server/ +!docker/dist-server/** diff --git a/Dockerfile.dist b/Dockerfile.dist new file mode 100644 index 0000000..4236d28 --- /dev/null +++ b/Dockerfile.dist @@ -0,0 +1,18 @@ +FROM golang:1.24-alpine AS builder + +WORKDIR /src + +COPY docker/dist-server/ ./ + +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/dist-server . + +FROM scratch + +WORKDIR /www + +COPY --from=builder /out/dist-server /dist-server +COPY dist/ /www/ + +EXPOSE 80 + +ENTRYPOINT ["/dist-server"] diff --git a/docker/dist-server/go.mod b/docker/dist-server/go.mod new file mode 100644 index 0000000..80bc90b --- /dev/null +++ b/docker/dist-server/go.mod @@ -0,0 +1,3 @@ +module dist-server + +go 1.24 diff --git a/docker/dist-server/main.go b/docker/dist-server/main.go new file mode 100644 index 0000000..adf127d --- /dev/null +++ b/docker/dist-server/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "log" + "net/http" + "os" + "path/filepath" + "strings" +) + +const ( + defaultPort = "80" + webRoot = "/www" + indexName = "index.html" +) + +func main() { + port := strings.TrimSpace(os.Getenv("PORT")) + if port == "" { + port = defaultPort + } + + server := &http.Server{ + Addr: ":" + port, + Handler: http.HandlerFunc(serve), + } + + log.Printf("dist server listening on :%s", port) + if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatal(err) + } +} + +func serve(w http.ResponseWriter, r *http.Request) { + requestPath := strings.TrimPrefix(filepath.Clean("/"+r.URL.Path), "/") + if requestPath == "." || requestPath == "" { + serveIndex(w, r) + return + } + + fullPath := filepath.Join(webRoot, filepath.FromSlash(requestPath)) + if info, err := os.Stat(fullPath); err == nil && !info.IsDir() { + applyAssetCacheHeaders(w, requestPath) + http.ServeFile(w, r, fullPath) + return + } + + serveIndex(w, r) +} + +func serveIndex(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Pragma", "no-cache") + w.Header().Set("Expires", "0") + http.ServeFile(w, r, filepath.Join(webRoot, indexName)) +} + +func applyAssetCacheHeaders(w http.ResponseWriter, requestPath string) { + if strings.EqualFold(requestPath, indexName) { + w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Pragma", "no-cache") + w.Header().Set("Expires", "0") + return + } + + if strings.HasPrefix(requestPath, "static/") { + w.Header().Set("Cache-Control", "public, max-age=31536000, immutable") + } +} diff --git a/index.html b/index.html index e76de1c..f13b71e 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@
- + -->