diff --git a/Dockerfile b/Dockerfile index c6ff34b..878b72f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /app COPY go.mod go.sum ./ RUN go mod download -COPY main.go ./ +COPY main.go index.html favicon.ico ./ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o nats-ui main.go # Runtime stage @@ -17,8 +17,7 @@ RUN apk --no-cache add ca-certificates tzdata && \ WORKDIR /app -COPY --from=builder /app/nats-ui . -COPY index.html ./ +COPY --from=builder /app/nats-ui ./ # config.yaml is in .gitignore; create default in image (override via volume at runtime) RUN printf '%s\n' \ diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..7108fc4 --- /dev/null +++ b/favicon.ico @@ -0,0 +1,1396 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + advisories/favicon.ico at main · nats-io/advisories · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ Skip to content + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + advisories + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + diff --git a/main.go b/main.go index aa97530..b693939 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,15 @@ package main import ( + "embed" "encoding/base64" "encoding/json" "fmt" "io" + "io/fs" "log" "net/http" "os" - "path/filepath" "strings" "sync" "time" @@ -18,6 +19,9 @@ import ( "gopkg.in/yaml.v3" ) +//go:embed index.html favicon.ico +var staticFS embed.FS + var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true @@ -305,23 +309,14 @@ func main() { } }() } - // Определяем путь к index.html - indexPath := "index.html" - if _, err := os.Stat(indexPath); os.IsNotExist(err) { - // Если не найден в текущей директории, пробуем рядом с исполняемым файлом - exePath, err := os.Executable() - if err == nil { - exeDir := filepath.Dir(exePath) - indexPath = filepath.Join(exeDir, "index.html") - } - } - + staticContent, _ := fs.Sub(staticFS, ".") + staticHandler := http.FileServer(http.FS(staticContent)) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/" { - http.NotFound(w, r) - return + if r.URL.Path == "/" { + r = r.Clone(r.Context()) + r.URL.Path = "/index.html" } - http.ServeFile(w, r, indexPath) + staticHandler.ServeHTTP(w, r) }) http.HandleFunc("/api/messages", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json")