added change to allow embedding the web portal
This commit is contained in:
16
daemon.go
16
daemon.go
@@ -1,20 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed web/dist
|
||||
var webFS embed.FS
|
||||
|
||||
type CommandPayload struct {
|
||||
Command string `json:"command"`
|
||||
}
|
||||
@@ -52,6 +58,12 @@ func StartDaemon(cfg *AppConfig, configPath string) error {
|
||||
mux.HandleFunc("/instances/getConfig", ds.handleGetConfig)
|
||||
mux.HandleFunc("/instances/setConfig", ds.handleSetConfig)
|
||||
|
||||
webContent, err := fs.Sub(webFS, "web/dist")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load embedded web assets: %w", err)
|
||||
}
|
||||
mux.Handle("/", http.FileServer(http.FS(webContent)))
|
||||
|
||||
corsWrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
||||
@@ -63,6 +75,10 @@ func StartDaemon(cfg *AppConfig, configPath string) error {
|
||||
}
|
||||
|
||||
authCheck := func() bool {
|
||||
if !strings.HasPrefix(r.URL.Path, "/instances/") {
|
||||
return true
|
||||
}
|
||||
|
||||
ds.RLock()
|
||||
defer ds.RUnlock()
|
||||
if ds.cfg.Daemon.AuthToken != "" {
|
||||
|
||||
2
web/dist/index.html
vendored
Normal file
2
web/dist/index.html
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html>
|
||||
<html><body>Web UI not embedded in this build.</body></html>
|
||||
Reference in New Issue
Block a user