package router import ( "net/http" "github.com/evanreichard/markdown-editor/internal/api" "github.com/evanreichard/markdown-editor/internal/logging" ) // New creates a new HTTP router with all routes configured func New(handlers *api.Handlers, staticDir string) *http.ServeMux { mux := http.NewServeMux() // API routes mux.HandleFunc("GET /api/files", handlers.ListFiles) mux.HandleFunc("GET /api/files/", handlers.GetFile) mux.HandleFunc("POST /api/files", handlers.CreateFile) mux.HandleFunc("PUT /api/files/", handlers.UpdateFile) mux.HandleFunc("DELETE /api/files/", handlers.DeleteFile) // Static assets if staticDir != "" { logging.Logger.WithField("static_dir", staticDir).Info("Static assets configured") fs := http.FileServer(http.Dir(staticDir)) mux.Handle("/", fs) } else { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Error(w, "Static assets directory not configured", http.StatusNotFound) }) } logging.Logger.Info("Router initialized with all routes") return mux }