向AWS API网关端点添加CORS支持
阅读文档: htttps:htttps:// docs。 aws.amazon.com/cdk/api/v1/docs/aws-apigateway-readme.html
对我而言,在端点上指定CORS不清楚它仅适用于该级别或所有子 -也有资源吗?
FE,
假设我在资源路径上添加了一种方法 - /否则
declare const productsResource: apigateway.Resource;
productsResource.addCorsPreflight({
allowOrigins: [ 'https://amazon.com' ],
allowMethods: [ 'GET', 'PUT' ]
Does that apply to /products/{productdId} as well?
});
我需要一个单独的AddCorsPreflight()来调用该子资源吗?
Reading the documentation: https://docs.aws.amazon.com/cdk/api/v1/docs/aws-apigateway-readme.html
It's not clear to me that specifying CORS on an endpoint means that it only applies to that level, or all the sub-resources as well?
F.e.,
let's say I add a method at resource path - /products and
declare const productsResource: apigateway.Resource;
productsResource.addCorsPreflight({
allowOrigins: [ 'https://amazon.com' ],
allowMethods: [ 'GET', 'PUT' ]
Does that apply to /products/{productdId} as well?
});
Or do I need a separate addCorsPreflight() call for that sub-resource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于如何定义该子资源。
如果是实际资源,我相信答案是肯定的 - 您确实需要为所有其他定义的资源定义它。对于任何而不是代理连接的给定资源,都会在您的资源上启用选项方法。
但是,如果它是代理终点(我希望它作为产品ID)与Lambda链接,则必须处理CORS前响应本身。
例如,您必须(不工作代码,您需要定义如何根据触发lambda的API Gateway的传入事件来知道这是否是前飞行的)
。 ://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html“ rel =” nofollow noreferrer“ how-to-cors.html
It depends on how that sub resource is defined.
If it is an actual Resource, i believe the answer is yes - you do need to define it for all other defined resources. Doing this for any given resource that is NOT a proxy connection will enable the OPTIONS method on your resource.
However if its a Proxy end point (which as a product ID i would expect) linked to a lambda it has to handle the Cors Preflight response itself.
Youd have to, for instance, (NOT working code, you need to define how to know if this is a preflight or not based on the incoming event from Api Gateway that triggers the lambda)
Find more information here: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html