fix: robustify analytics handlers and fix auth middleware scope
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

Moved AuthMiddleware to /v1 group only. Added COALESCE and empty result handling to analytics SQL queries to prevent 500 errors on empty databases.
This commit is contained in:
2026-03-19 12:28:56 -04:00
parent 9c64a8fe42
commit 1f3adceda4
2 changed files with 34 additions and 25 deletions

View File

@@ -74,7 +74,8 @@ func NewServer(cfg *config.Config, database *db.DB) *Server {
}
func (s *Server) setupRoutes() {
s.router.Use(middleware.AuthMiddleware(s.database))
// Global middleware should only be for logging/recovery
// Auth is specific to groups
// Static files
s.router.StaticFile("/", "./static/index.html")
@@ -86,7 +87,9 @@ func (s *Server) setupRoutes() {
// WebSocket
s.router.GET("/ws", s.handleWebSocket)
// API V1 (External LLM Access)
v1 := s.router.Group("/v1")
v1.Use(middleware.AuthMiddleware(s.database))
{
v1.POST("/chat/completions", s.handleChatCompletions)
v1.GET("/models", s.handleListModels)