package main import ( "fmt" "log" "log/slog" "net/http" "os" "strings" "gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/config" "gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/handlers" "gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/middleware" ) func main() { // Set up structured logging. slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ Level: slog.LevelInfo, }))) cfg, err := config.Load() if err != nil { log.Fatalf("configuration error: %v", err) } // Determine if cookies should be marked Secure (disable for local dev). secureCookies := !strings.HasPrefix(cfg.ListenAddr, "localhost") && !strings.HasPrefix(cfg.ListenAddr, "127.0.0.1") mux := http.NewServeMux() // Health endpoint (no auth required). mux.HandleFunc("GET /health", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintln(w, "ok") }) // Settings handler. settingsHandler := &handlers.SettingsHandler{ SessionSecret: cfg.SessionSecret, SecureCookies: secureCookies, } mux.HandleFunc("/settings", settingsHandler.ServeHTTP) // Static file server. mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) // Placeholder dashboard (will be replaced in issue #4/#5). mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") fmt.Fprintln(w, "

Gitea Mobile

Dashboard coming soon.

") }) // Apply middleware chain: logging -> auth. var handler http.Handler = mux handler = middleware.Auth(cfg.SessionSecret)(handler) handler = middleware.Logging()(handler) slog.Info("server starting", "addr", cfg.ListenAddr, "gitea_url", cfg.GiteaURL) if err := http.ListenAndServe(cfg.ListenAddr, handler); err != nil { log.Fatalf("server error: %v", err) } }