GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-dart
CORS support
- Dominant language
- Dart
- Stars
- 548
- Forks
- 49
- Avg merge
- 53m
- Merged PRs (30d)
- 1
Description
If a request comes from a script running under a different origin (for our purposes here, a [tuple](https://html.spec.whatwg.org/multipage/origin.html#concept-origin-tuple) that includes a host and port) from the origin that is hosting a function app, the request will fail due to lack of cross-origin resource sharing ([CORS protocol](https://fetch.spec.whatwg.org/#http-cors-protocol)) support.
For background, browsers restrict cross-origin HTTP requests initiated from scripts for security purposes, so if a browser runs, for example, a Flutter app loaded from a different origin than the origin hosting, for example, a Dart function app, the request will fail if the function app doesn't support CORS.
As part of supporting CORS, a function app must be able to handle the [CORS preflight](https://fetch.spec.whatwg.org/#cors-preflight-request), which is sent as an HTTP [OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS) request.
What would be useful for this situation is to add CORS support to the framework that would allow specifying a CORS policy, possible as metadata annotation or as an API, for setting a policy. For inspiration, see the Node.js [cors package](https://expressjs.com/en/resources/middleware/cors.html).
References:
* https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
* https://fetch.spec.whatwg.org/#http-cors-protocol
* https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Contributor guide
Assessment
This issue has not been assessed yet.