Files
fes/modules/server/server.go
2026-02-14 08:26:56 -05:00

40 lines
730 B
Go

package server
import (
"fes/modules/config"
"fes/modules/ui"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
)
var Routes map[string]string
var Sets DeclarativeSets
func Start(dir string) {
if err := os.Chdir(dir); err != nil {
ui.Error(fmt.Sprintf("failed to change directory to %s", dir), err)
}
root := filepath.Clean(dir)
if root == "." {
if res, err := filepath.Abs(root); err == nil {
root = filepath.Base(res)
} else {
ui.Error("failed to get absolute path", err)
}
}
ui.Log("running root=%s, port=%d.", root, *config.Port)
Routes = loadDirs()
http.HandleFunc("/", httpHandler)
ui.Log("Server initialized")
log.Fatal(http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", *config.Port), nil))
}