package api import ( "net/http" ) func (h *Handler) SetupRoutes(mux *http.ServeMux) { // Static files mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "web/index.html") }) mux.HandleFunc("GET /css/", func(w http.ResponseWriter, r *http.Request) { http.StripPrefix("/css/", http.FileServer(http.Dir("web/css"))).ServeHTTP(w, r) }) mux.HandleFunc("GET /js/", func(w http.ResponseWriter, r *http.Request) { http.StripPrefix("/js/", http.FileServer(http.Dir("web/js"))).ServeHTTP(w, r) }) // API routes - Profile mux.HandleFunc("GET /api/profile", h.GetProfile) mux.HandleFunc("POST /api/profile", h.UpdateProfile) // API routes - Experiences mux.HandleFunc("GET /api/experiences", h.GetExperiences) mux.HandleFunc("POST /api/experiences", h.CreateExperience) mux.HandleFunc("PUT /api/experiences", h.UpdateExperience) mux.HandleFunc("DELETE /api/experiences", h.DeleteExperience) // API routes - Educations mux.HandleFunc("GET /api/educations", h.GetEducations) mux.HandleFunc("POST /api/educations", h.CreateEducation) mux.HandleFunc("PUT /api/educations", h.UpdateEducation) mux.HandleFunc("DELETE /api/educations", h.DeleteEducation) // API routes - Skills mux.HandleFunc("GET /api/skills", h.GetSkills) mux.HandleFunc("POST /api/skills", h.CreateSkill) mux.HandleFunc("PUT /api/skills", h.UpdateSkill) mux.HandleFunc("DELETE /api/skills", h.DeleteSkill) // API routes - Work Samples mux.HandleFunc("GET /api/samples", h.GetWorkSamples) mux.HandleFunc("POST /api/samples", h.CreateWorkSample) mux.HandleFunc("PUT /api/samples", h.UpdateWorkSample) mux.HandleFunc("DELETE /api/samples", h.DeleteWorkSample) // API routes - Templates mux.HandleFunc("GET /api/templates", h.GetTemplates) mux.HandleFunc("POST /api/templates", h.CreateTemplate) mux.HandleFunc("PUT /api/templates", h.UpdateTemplate) mux.HandleFunc("DELETE /api/templates", h.DeleteTemplate) mux.HandleFunc("POST /api/templates/active", h.SetActiveTemplate) mux.HandleFunc("POST /api/templates/preview", h.PreviewTemplate) mux.HandleFunc("POST /api/render", h.RenderResume) mux.HandleFunc("GET /api/placeholders", h.GetPlaceholders) // API routes - Applications mux.HandleFunc("GET /api/applications", h.GetApplications) mux.HandleFunc("POST /api/applications", h.CreateApplication) mux.HandleFunc("PUT /api/applications", h.UpdateApplication) mux.HandleFunc("DELETE /api/applications", h.DeleteApplication) mux.HandleFunc("GET /api/applications/detail", h.GetApplicationDetail) // API routes - Q&A mux.HandleFunc("POST /api/qa", h.CreateQA) mux.HandleFunc("PUT /api/qa", h.UpdateQA) mux.HandleFunc("DELETE /api/qa", h.DeleteQA) // API routes - Saved Resume YAML mux.HandleFunc("GET /api/saved-resume", h.GetSavedResume) mux.HandleFunc("POST /api/saved-resume", h.SaveResume) mux.HandleFunc("PUT /api/saved-resume", h.UpdateSavedResume) mux.HandleFunc("DELETE /api/saved-resume", h.DeleteSavedResume) // API routes - Resume Data mux.HandleFunc("GET /api/resume-data", h.GetResumeData) mux.HandleFunc("GET /api/export", h.ExportData) mux.HandleFunc("POST /api/import", h.ImportData) // API routes - Generation mux.HandleFunc("POST /api/generate/resume", h.GenerateResume) mux.HandleFunc("POST /api/generate/cover-letter", h.GenerateCoverLetter) mux.HandleFunc("POST /api/generate/answer", h.GenerateAnswer) // API routes - Streaming Generation mux.HandleFunc("POST /api/stream/resume", h.StreamResume) mux.HandleFunc("POST /api/stream/cover-letter", h.StreamCoverLetter) mux.HandleFunc("POST /api/stream/answer", h.StreamAnswer) // API routes - LLM mux.HandleFunc("POST /api/llm/test", h.TestLLMConnection) // Config endpoint (returns LLM config without exposing API key) mux.HandleFunc("GET /api/config", func(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, map[string]interface{}{ "llm_base_url": r.URL.Query().Get("base_url"), "llm_model": r.URL.Query().Get("model"), }) }) // Health check mux.HandleFunc("GET /api/health", func(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, map[string]string{"status": "ok"}) }) } // Cors middleware func CorsMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-LLM-Base, X-LLM-Model, X-LLM-Key") if r.Method == "OPTIONS" { w.WriteHeader(http.StatusOK) return } next.ServeHTTP(w, r) }) }