Repository navigation
fix(examples): wire CORS_ORIGINS into the CORS middleware in 10-production-boilerplate - #40
Open
hashi-divyansh wants to merge 1 commit into
Open
hashi-divyansh wants to merge 1 commit into
hashi-divyansh wants to merge 1 commit into
Conversation
CORSOrigins wrapped the whole comma-separated env value in a one-element []string and was never used: main.go called middleware.CORS(), which allows any origin. Make CORSOrigins a string (CORSConfig.AllowOrigins is already a comma-separated list) and pass it to middleware.CORSWithConfig.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #33 review. In
examples/10-production-boilerplate,CORS_ORIGINSwas loaded but never used:config.gowrapped the whole comma-separated value in a one-element[]string, andmain.gousedmiddleware.CORS()(allow any origin).Config.CORSOriginsis now astring.CORSConfig.AllowOriginsis already a comma-separated list, so no splitting is needed.main.gousesmiddleware.CORSWithConfig(middleware.CORSConfig{AllowOrigins: cfg.CORSOrigins}).*allows any origin.Behavior change
*(any)CORS_ORIGINS(defaulthttp://localhost:3000,http://localhost:8080)*Content-Type,Accept,Authorization(CORSWithConfigdefault; covers this API)Set
CORS_ORIGINS=*to keep the old allow-all behavior.Testing
go mod tidy && go build ./...,go vet ./...,gofmt,go test -race ./...OPTIONSwithAuthorization, Content-Type) andGET /healthwith anOriginheader:http://localhost:3000allowed,http://evil.examplegets no CORS headersCORS_ORIGINS=https://app.example.com: that origin allowed,localhost:3000gets no CORS headersCORS_ORIGINS=*: any origin getsAccess-Control-Allow-Origin: *