Files
junk2jive-server/internal/routes/routes.go
2025-05-06 13:31:09 -07:00

39 lines
957 B
Go

package routes
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
"gitea.miguelmuniz.com/junk2jive-server/internal/config"
"gitea.miguelmuniz.com/junk2jive-server/internal/handlers"
)
func SetupRoutes(cfg *config.Config) *chi.Mux {
r := chi.NewRouter()
// Middleware
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Content-Type"},
AllowCredentials: true,
}))
// Static files
fileServer := http.FileServer(http.Dir("./static"))
r.Handle("/static/*", http.StripPrefix("/static", fileServer))
// API routes
r.Get("/", handlers.HomeHandler)
r.Route("/api", func(r chi.Router) {
r.Post("/text-prompt", handlers.TextPromptHandler(cfg))
r.Post("/ai-prompt", handlers.VisualAIHandler(cfg))
})
return r
}