Skip to content

Commit

Permalink
cors attempt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebRose committed Apr 12, 2024
1 parent 1916933 commit 4a8d8a7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func InitialMigration() {

func handleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)

// Handler & Middleware
loadEnvs()
origins := os.Getenv("ORIGIN_ALLOWED")
originsOk := handlers.AllowedOrigins([]string{origins})
headersOk := handlers.AllowedHeaders([]string{"Content-Type", "Authorization", "Accept", "X-Requested-With", "Access-Control-Request-Method", "Access-Control-Request-Headers"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
handler := handlers.CORS(originsOk, methodsOk, headersOk)(myRouter)
myRouter.Use(middleware.GzipMiddleware)

// Health Controls
Expand Down Expand Up @@ -277,14 +285,7 @@ func handleRequests() {
// Easter Controls
myRouter.HandleFunc("/easter/egg/collude/", controller.CollusionButton).Methods("POST")

// Handle Controls
// handler := cors.AllowAll().Handler(myRouter)
loadEnvs()
origins := os.Getenv("ORIGIN_ALLOWED")
originsOk := handlers.AllowedOrigins([]string{origins})
headersOk := handlers.AllowedHeaders([]string{"Content-Type", "Authorization", "Accept", "Access-Control-Request-Method", "Access-Control-Request-Headers"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
log.Fatal(http.ListenAndServe(":5001", handlers.CORS(originsOk, methodsOk, headersOk)(myRouter)))
log.Fatal(http.ListenAndServe(":5001", handler))
}

func loadEnvs() {
Expand Down

0 comments on commit 4a8d8a7

Please sign in to comment.