add provisional CORS support

This commit is contained in:
2025-05-25 13:00:29 -04:00
parent 8e4a336510
commit 04c83cccb9
8 changed files with 547 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import (
"git.dubyatp.xyz/chat-api-server/db"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
"github.com/go-chi/docgen"
"github.com/go-chi/render"
)
@@ -34,6 +35,15 @@ func Start() {
r := chi.NewRouter()
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"http://localhost:5000"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: true,
MaxAge: 300, // Maximum value for preflight request cache
}))
r.Use(middleware.RequestID)
r.Use(RequestLog)
r.Use(middleware.Recoverer)