Update architecture
All checks were successful
CI/CD / Lint & Test (push) Successful in 1m0s
CI/CD / Build & Push Docker image (hub.p42.ru) (push) Successful in 2m48s

This commit is contained in:
admin 2026-02-09 13:36:34 +07:00
parent 262b50ae7d
commit d3b60c5a45
3 changed files with 1409 additions and 19 deletions

View File

@ -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' \

1396
favicon.ico Normal file

File diff suppressed because one or more lines are too long

27
main.go
View File

@ -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")