Skip to content

Commit

Permalink
Cors module does not work as middleware (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
aburgel authored Jun 27, 2019
1 parent 53d777e commit 91efdf9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL = /bin/sh

VERSION=1.0.0
VERSION=1.0.1
BUILD=`git rev-parse HEAD`

LDFLAGS=-ldflags "-w -s \
Expand Down
9 changes: 5 additions & 4 deletions fakeserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func loggingMiddleware(next http.Handler) http.Handler {
})
}

func corsMiddleware(next http.Handler) http.Handler {
func createCors() *cors.Cors {
return cors.New(cors.Options{
AllowCredentials: true,
AllowedHeaders: []string{"authorization"},
Expand Down Expand Up @@ -59,7 +59,7 @@ func corsMiddleware(next http.Handler) http.Handler {
}
return false
},
}).Handler(next)
})
}

// Start the server
Expand All @@ -72,11 +72,12 @@ func Start(port int) {
s.routes()

r.Use(loggingMiddleware)
r.Use(corsMiddleware)

handler := createCors().Handler(r)

listenOn := fmt.Sprintf("127.0.0.1:%d", port)
logger.Printf("testtrack server listening on %s", listenOn)
logger.Fatalf("fatal - %s", http.ListenAndServe(listenOn, r))
logger.Fatalf("fatal - %s", http.ListenAndServe(listenOn, handler))
}

func (s *server) handleGet(pattern string, responseFunc func() (interface{}, error)) {
Expand Down

0 comments on commit 91efdf9

Please sign in to comment.