mirror of
https://github.com/sartoopjj/thefeed.git
synced 2026-05-19 07:34:35 +03:00
feat: add host flag to configure web UI listen address
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
+9
-2
@@ -15,6 +15,7 @@ import (
|
||||
func main() {
|
||||
dataDir := flag.String("data-dir", "./thefeeddata", "Data directory for config, cache, and sessions")
|
||||
port := flag.Int("port", 8080, "Web UI port")
|
||||
host := flag.String("host", "127.0.0.1", "Web UI listen address (host), use 0.0.0.0 to expose to LAN")
|
||||
password := flag.String("password", "", "Admin password for web UI (empty = no auth)")
|
||||
showVersion := flag.Bool("version", false, "Show version and exit")
|
||||
flag.Usage = func() {
|
||||
@@ -28,13 +29,19 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
srv, err := web.New(*dataDir, *port, *password)
|
||||
srv, err := web.New(*dataDir, *port, *host, *password)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start: %v", err)
|
||||
}
|
||||
|
||||
// Try to open browser automatically
|
||||
url := fmt.Sprintf("http://127.0.0.1:%d", *port)
|
||||
|
||||
// Open browser on the chosen host (localhost if default)
|
||||
browserHost := *host
|
||||
if browserHost == "0.0.0.0" {
|
||||
browserHost = "127.0.0.1"
|
||||
}
|
||||
url := fmt.Sprintf("http://%s:%d", browserHost, *port)
|
||||
go openBrowser(url)
|
||||
|
||||
if err := srv.Run(); err != nil {
|
||||
|
||||
+6
-3
@@ -87,6 +87,7 @@ type lastScanData struct {
|
||||
type Server struct {
|
||||
dataDir string
|
||||
port int
|
||||
host string
|
||||
password string // admin password; empty means no auth
|
||||
|
||||
mu sync.RWMutex
|
||||
@@ -139,7 +140,7 @@ type Server struct {
|
||||
}
|
||||
|
||||
// New creates a new web server.
|
||||
func New(dataDir string, port int, password string) (*Server, error) {
|
||||
func New(dataDir string, port int, host string, password string) (*Server, error) {
|
||||
if err := os.MkdirAll(dataDir, 0700); err != nil {
|
||||
return nil, fmt.Errorf("create data dir: %w", err)
|
||||
}
|
||||
@@ -156,6 +157,7 @@ func New(dataDir string, port int, password string) (*Server, error) {
|
||||
s := &Server{
|
||||
dataDir: dataDir,
|
||||
port: port,
|
||||
host: host,
|
||||
password: password,
|
||||
messages: make(map[int][]protocol.Message),
|
||||
clients: make(map[chan string]struct{}),
|
||||
@@ -230,9 +232,10 @@ func (s *Server) Run() error {
|
||||
mux.HandleFunc("/api/scanner/presets", s.handleScannerPresets)
|
||||
mux.HandleFunc("/", s.handleIndex)
|
||||
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", s.port)
|
||||
// Listen on the specified host (default 127.0.0.1)
|
||||
addr := fmt.Sprintf("%s:%d", s.host, s.port)
|
||||
log.Printf("thefeed client %s", version.Version)
|
||||
fmt.Printf("\n Open in browser: http://%s\n\n", addr)
|
||||
fmt.Printf("\n Open in browser: http://%s:%d\n\n", s.host, s.port)
|
||||
|
||||
if s.fetcher != nil {
|
||||
if ls := s.loadLastScan(); ls != nil {
|
||||
|
||||
Reference in New Issue
Block a user