Update architecture
This commit is contained in:
parent
262b50ae7d
commit
d3b60c5a45
@ -6,7 +6,7 @@ WORKDIR /app
|
|||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
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
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o nats-ui main.go
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
@ -17,8 +17,7 @@ RUN apk --no-cache add ca-certificates tzdata && \
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/nats-ui .
|
COPY --from=builder /app/nats-ui ./
|
||||||
COPY index.html ./
|
|
||||||
|
|
||||||
# config.yaml is in .gitignore; create default in image (override via volume at runtime)
|
# config.yaml is in .gitignore; create default in image (override via volume at runtime)
|
||||||
RUN printf '%s\n' \
|
RUN printf '%s\n' \
|
||||||
|
|||||||
1396
favicon.ico
Normal file
1396
favicon.ico
Normal file
File diff suppressed because one or more lines are too long
27
main.go
27
main.go
@ -1,14 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -18,6 +19,9 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed index.html favicon.ico
|
||||||
|
var staticFS embed.FS
|
||||||
|
|
||||||
var upgrader = websocket.Upgrader{
|
var upgrader = websocket.Upgrader{
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
return true
|
return true
|
||||||
@ -305,23 +309,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
// Определяем путь к index.html
|
staticContent, _ := fs.Sub(staticFS, ".")
|
||||||
indexPath := "index.html"
|
staticHandler := http.FileServer(http.FS(staticContent))
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/" {
|
if r.URL.Path == "/" {
|
||||||
http.NotFound(w, r)
|
r = r.Clone(r.Context())
|
||||||
return
|
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) {
|
http.HandleFunc("/api/messages", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user