Skip to content

Commit

Permalink
feat: support sub domain for cors (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Apr 25, 2022
1 parent ec3e026 commit 5c9fae7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rest/internal/cors/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cors

import (
"net/http"
"strings"

"github.com/zeromicro/go-zero/rest/internal/response"
)
Expand Down Expand Up @@ -81,7 +82,7 @@ func isOriginAllowed(allows []string, origin string) bool {
return true
}

if o == origin {
if strings.HasSuffix(origin, o) {
return true
}
}
Expand Down
6 changes: 6 additions & 0 deletions rest/internal/cors/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
reqOrigin: "http://local",
expect: "http://local",
},
{
name: "allow sub origins",
origins: []string{"local", "remote"},
reqOrigin: "sub.local",
expect: "sub.local",
},
{
name: "allow all origins",
reqOrigin: "http://local",
Expand Down

0 comments on commit 5c9fae7

Please sign in to comment.