-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set arbitrary headers for APIG (will enable CORS) #70
Comments
I think having something similar to what the console has via "Enable CORS" would be great to add. Marking as a feature request. |
Even if I go into AWS API Gateway console and select 'Access-Control-Allow-Origin' it still gives the error in the browser of not having the CORS header? |
👍 very important for me as well to be able to enable CORS from chalice |
+1 - having the ability to enable CORS on deploy would be fantastic. @zaga1 you'll need to enable CORS for each resource then deploy the API from the console. |
Is everyone enabling CORS in the console right now? Or is no one really building APIs meant for the browser with this? Would really like to try this, but don't have any server to server use cases. |
Yes, this is how I'm doing this. It's a bit more manual than I'd like but it will do for now. |
Taking a look now. |
I've been playing around with this feature and I think there's a few use cases I can envision. Would like to hear what others think about this: 1. Enable CORS for a single route:
This would mimic the behavior of the "Enable CORS" in the console. Would default to 2. Enable CORs for the entire app. If you just want cors enabled for every view function, you can specify this when creating your app:
3. Customized CORS configuration
Optionally, I could just use a single args, Would those three cases cover most people's usage? |
I like the above. One thing that I'd want is to ensure that the CORS headers are on all the response codes, not just 200. Otherwise I'll still have to go in and update 400, 403, 404, etc. |
Good point, I'll be sure to add this to all status codes. |
@jamesls Sounds like a good plan! |
@jamesls definitely looking good! I ran into this issue a while ago and was thinking about building this in. Any way I can help you, perhaps? |
The fact that CORS support here just automatically gives you The above warning is not mentioned in the Chalice docs... do we trust every consumer to understand how CORS works and what CORS is just a best-intention spec anyway (you have to trust the browser), but I don't think CORS should have shipped without something like the |
@jackrk thanks for the feedback. We're working on adding the CORSConfig option. |
Implemented in #311 |
The CORS support is nice, but I see that the cors=True wasn't made part of Chalice instantiation. I have lots of routes and it would be nicer if I could just turn it on for everything. Not sure what others think. |
@dmulter I would like to turn it on for everything too via passing an option during instantiation of the app. |
@jamesls @stealthycoin: We see that the support is now added for |
Currently I can define a resource like this:
@app.route('/scalars', methods=['GET', 'OPTIONS'])
def scalars():
return { 'mau': 27048, 'wau: 7003 }'
The OPTIONS will help me with enabling CORS in APIG But I'm still missing the 'Access-Control-Allow-Origin' header, so I enable it manually in the console after each deploy.
One approach would be to configure headers in the method.
Another would be to call the "Enable CORS" magic button in APIG.
WDYT?
The text was updated successfully, but these errors were encountered: