Closed Tomilla closed 3 years ago
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: To fully approve this pull request, please assign additional approvers. We suggest the following additional approver: supereagle
Assign the PR to them by writing /assign @supereagle
in a comment when ready.
The full list of commands accepted by this bot can be found here.
The pull request process is described here
I think it would be more appropriate for us to make this a middleware, it would be simpler and easier to use (e.g. we can configure different rules on different API groups).
@Tomilla: PR needs rebase.
I think it would be more appropriate for us to make this a middleware, it would be simpler and easier to use (e.g. we can configure different rules on different API groups).
Okay. This plugin was defined to apply CORS policy to the root path. I respect your approach very much. During the transition period, I temporarily use this PR in my projects.
What this PR does / why we need it:
Add a plugin to handle to handle CORS(Cross-Origin Resource Sharing) related requests(via simple encapsulation of this go package https://github.com/rs/cors). All its Supported Options as follow:
AllowedOrigins
: a list of origins a cross-domain request can be executed from(for example the domain which hosts front-end pages is different from the back-end domain)AllowedMethods
: A list of methods the client is allowed to use with cross-domain requests(for example:GET
,POST
,PATCH
,DELETE
)AllowOriginFunc
func (origin string) bool
: A custom function to validate the originAllowOriginRequestFunc
func (r *http.Request origin string) bool
: A custom function to validate the originAllowedHeaders
[]string
: A list of non simple headers the client is allowed to use with cross-domain requests.ExposedHeaders
[]string
: Indicates which headers are safe to expose to the API of a CORS API specificationAllowCredentials
bool: Indicates whether the request can include user credentials like cookies, HTTP authentication or client side SSL certificates.Which issue(s) this PR is related to (optional, link to 3rd issue(s)):
Fixes #
Reference to #
Special notes for your reviewer:
/cc @iawia002
related code https://github.com/caicloud/nirvana/blob/98146ec4aa3cdbada6878d1f560494d15b4c8bf6/config/config.go#L333-L492
Code freeze questions
Why this PR is absolutely necessary for this version? Paste a screenshot of smoke testing docs if you could.
Error: Access to fetch at 'http://localhost:8080/apis/v1/messages?count=10' from origin 'http://localhost:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
kind
field to struct configField https://github.com/caicloud/nirvana/blob/98146ec4aa3cdbada6878d1f560494d15b4c8bf6/config/config.go#L154-L162kind
), Is there a way to detect a pointer is function or not duringregisterFields
?Release note:
Nirvana
.