Skip to content

Commit 91efdf9

Browse files
authored
Cors module does not work as middleware (#44)
1 parent 53d777e commit 91efdf9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL = /bin/sh
22

3-
VERSION=1.0.0
3+
VERSION=1.0.1
44
BUILD=`git rev-parse HEAD`
55

66
LDFLAGS=-ldflags "-w -s \

fakeserver/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func loggingMiddleware(next http.Handler) http.Handler {
3131
})
3232
}
3333

34-
func corsMiddleware(next http.Handler) http.Handler {
34+
func createCors() *cors.Cors {
3535
return cors.New(cors.Options{
3636
AllowCredentials: true,
3737
AllowedHeaders: []string{"authorization"},
@@ -59,7 +59,7 @@ func corsMiddleware(next http.Handler) http.Handler {
5959
}
6060
return false
6161
},
62-
}).Handler(next)
62+
})
6363
}
6464

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

7474
r.Use(loggingMiddleware)
75-
r.Use(corsMiddleware)
75+
76+
handler := createCors().Handler(r)
7677

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

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

0 commit comments

Comments
 (0)