tsk-4: Fixed code

This commit is contained in:
phoenix
2025-12-13 15:29:54 -05:00
parent fa8c7062fc
commit 09744d4cdf
+11 -12
View File
@@ -12,7 +12,7 @@ import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware" "github.com/go-chi/chi/v5/middleware"
"github.com/rs/cors" "github.com/go-chi/cors"
"github.com/swaggo/http-swagger/v2" "github.com/swaggo/http-swagger/v2"
_ "git.kundeng.us/phoenix/textsender-api/docs" _ "git.kundeng.us/phoenix/textsender-api/docs"
@@ -93,6 +93,15 @@ func main() {
router := chi.NewRouter() router := chi.NewRouter()
// Configure CORS
router.Use( cors.Handler(cors.Options{
AllowedOrigins: []string{fmt.Sprintf("http://localhost:%s", config.PORT), "http://localhost:5173", "https://textsender.com"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link", "X-Total-Count"},
AllowCredentials: true,
MaxAge: 300, // 5 minutes
}))
router.Use(middleware.Logger) router.Use(middleware.Logger)
router.Use(middleware.Recoverer) router.Use(middleware.Recoverer)
router.Use(middleware.Timeout(60 * time.Second)) router.Use(middleware.Timeout(60 * time.Second))
@@ -116,20 +125,10 @@ func main() {
httpSwagger.URL(fmt.Sprintf("http://localhost:%s/swagger/doc.json", config.PORT)), httpSwagger.URL(fmt.Sprintf("http://localhost:%s/swagger/doc.json", config.PORT)),
)) ))
// Configure CORS
c := cors.New(cors.Options{
AllowedOrigins: []string{fmt.Sprintf("http://localhost:%s", config.PORT), "https://textsender.com"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link", "X-Total-Count"},
AllowCredentials: true,
MaxAge: 300, // 5 minutes
})
// Start server // Start server
server := &http.Server{ server := &http.Server{
Addr: ":" + cfg.ServerPort, Addr: ":" + cfg.ServerPort,
Handler: c.Handler(router), Handler: router,
ReadTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second, WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second, IdleTimeout: 60 * time.Second,