Skip to content

Commit d05643d

Browse files
authored
Merge pull request #33 from Betterment/jmileham/custom_allowed_origins
Allow custom CORS origins
2 parents 587ddb5 + c40fcf4 commit d05643d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL = /bin/sh
22

3-
VERSION=0.9.5
3+
VERSION=0.9.6
44
BUILD=`git rev-parse HEAD`
55

66
LDFLAGS=-ldflags "-w -s \

Diff for: fakeserver/server.go

+22-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net"
99
"net/http"
10+
"os"
1011
"strings"
1112
"sync"
1213
"time"
@@ -43,10 +44,28 @@ func Start() {
4344
AllowCredentials: true,
4445
AllowedHeaders: []string{"authorization"},
4546
AllowOriginFunc: func(origin string) bool {
46-
dotTest := strings.HasSuffix(origin, ".test")
47-
localhost := origin == "localhost"
47+
allowedOrigins, ok := os.LookupEnv("TESTTRACK_ALLOWED_ORIGINS")
48+
if ok {
49+
for _, allowedOrigin := range strings.Split(allowedOrigins, ",") {
50+
allowedOrigin = strings.Trim(allowedOrigin, " ")
51+
if strings.HasSuffix(origin, allowedOrigin) {
52+
return true
53+
}
54+
}
55+
} else {
56+
// .test cannot be registered so we allow it by default
57+
if strings.HasSuffix(origin, ".test") {
58+
return true
59+
}
60+
}
61+
if origin == "localhost" {
62+
return true
63+
}
4864
ip := net.ParseIP(origin)
49-
return dotTest || localhost || (ip != nil && ip.IsLoopback())
65+
if ip != nil && ip.IsLoopback() {
66+
return true
67+
}
68+
return false
5069
},
5170
}).Handler(r)))
5271
}

0 commit comments

Comments
 (0)