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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed web/dist
|
||||||
|
var webFS embed.FS
|
||||||
|
|
||||||
type CommandPayload struct {
|
type CommandPayload struct {
|
||||||
Command string `json:"command"`
|
Command string `json:"command"`
|
||||||
}
|
}
|
||||||
@@ -52,6 +58,12 @@ func StartDaemon(cfg *AppConfig, configPath string) error {
|
|||||||
mux.HandleFunc("/instances/getConfig", ds.handleGetConfig)
|
mux.HandleFunc("/instances/getConfig", ds.handleGetConfig)
|
||||||
mux.HandleFunc("/instances/setConfig", ds.handleSetConfig)
|
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) {
|
corsWrappedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
||||||
@@ -63,6 +75,10 @@ func StartDaemon(cfg *AppConfig, configPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
authCheck := func() bool {
|
authCheck := func() bool {
|
||||||
|
if !strings.HasPrefix(r.URL.Path, "/instances/") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
ds.RLock()
|
ds.RLock()
|
||||||
defer ds.RUnlock()
|
defer ds.RUnlock()
|
||||||
if ds.cfg.Daemon.AuthToken != "" {
|
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