tsk-4: Adding CORS support
This commit is contained in:
+12
-1
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/rs/cors"
|
||||
"github.com/swaggo/http-swagger/v2"
|
||||
|
||||
_ "git.kundeng.us/phoenix/textsender-api/docs"
|
||||
@@ -115,10 +116,20 @@ func main() {
|
||||
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
|
||||
server := &http.Server{
|
||||
Addr: ":" + cfg.ServerPort,
|
||||
Handler: router,
|
||||
Handler: c.Handler(router),
|
||||
ReadTimeout: 15 * time.Second,
|
||||
WriteTimeout: 15 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
|
||||
Reference in New Issue
Block a user