FAILURE STATE

This commit is contained in:
2026-01-01 11:41:43 -05:00
parent 9364df2645
commit 7fbf8ae8c2
25 changed files with 1713 additions and 6 deletions

View File

@@ -1,11 +1,10 @@
package server
import (
"context"
"fes/modules/config"
"fes/modules/ui"
"fmt"
"github.com/pelletier/go-toml/v2"
lua "github.com/yuin/gopher-lua"
"html/template"
"io/fs"
"net/http"
@@ -15,6 +14,9 @@ import (
"sort"
"strings"
"time"
"github.com/pelletier/go-toml/v2"
lua "github.com/yuin/gopher-lua"
)
/* this is the request data we pass over the bus to the application, via the fes.bus interface */
@@ -409,9 +411,13 @@ func readArchive(w http.ResponseWriter, route string) error {
}
/* start the Fes server */
func Start(dir string) error {
func Start(dir string) (*http.Server, error) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return nil, fmt.Errorf("directory does not exist: %s", dir)
}
if err := os.Chdir(dir); err != nil {
return ui.Error(fmt.Sprintf("failed to change directory to %s", dir), err)
return nil, fmt.Errorf("failed to change directory to %s: %w", dir, err)
}
cfg := parseConfig()
@@ -467,5 +473,22 @@ func Start(dir string) error {
})
fmt.Printf("Server is running on http://localhost:%d\n", *config.Port)
return http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", *config.Port), nil)
srv := &http.Server{
Addr: fmt.Sprintf("0.0.0.0:%d", *config.Port),
}
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
ui.Error("Server failed: %v", err)
}
}()
return srv, nil
}
func Stop(srv *http.Server) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
return srv.Shutdown(ctx)
}

File diff suppressed because it is too large Load Diff