added change to allow embedding the web portal

This commit is contained in:
2026-06-11 21:45:26 -05:00
parent d610a84718
commit dcee28d00f
2 changed files with 18 additions and 0 deletions

View File

@@ -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
View File

@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html><body>Web UI not embedded in this build.</body></html>