带有Angular的AWS API Gateway [英] AWS API Gateway with Angular

查看:127
本文介绍了带有Angular的AWS API Gateway的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人获得了可与Angular.js前端一起使用的AWS API网关?我有一个lambda函数,该函数通过API网关中的POST方法公开.我按照此文档所示设置了标头: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

Has anyone gotten the AWS API Gateway to work with an Angular.js front-end? I have a lambda function that's exposed via a POST method in the API Gateway. I set up the headers as indicated by this doc: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

我在Postman中测试了它,效果很好.我不必做任何特殊的事情,但是当我执行$http.post()调用时,我只在请求的资源上出现了No 'Access-Control-Allow-Origin'标头.因此,不允许访问源http://localhost:9000.响应以HTTP status code 500.作为响应.

I tested it in Postman and it works great. I didn't have to do anything special, but when I do the $http.post() call I only get No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://localhost:9000 is therefore not allowed access. The response had HTTP status code 500. as the response.

推荐答案

此处是Api Gateway团队.

Api Gateway team here.

希望到目前为止,您已经在控制台中签出了新的启用CORS"功能.即使您的开发工作流程不在控制台之外,您也可以快速设置测试API并查看控制台为您设置的标头配置,然后将其复制到Swagger def或您提供的任何解决方案中.

Hopefully by now you've checked out the new 'Enable CORS' feature in the console. Even if your dev workflow is outside the console, you could quickly setup a test API and look at the header configurations that the console sets up for you, then copy those to your Swagger def or whatever solution you've come up with.

无论哪种情况,文档指南均应适用.您将需要3个标题:Access-Control-Allow-Methods,Access-Control-Allow-Origin和Access-Control-Allow-Header.这些值将取决于您的API.

The docs guide should still apply in either case. You'll need the 3 headers: Access-Control-Allow-Methods, Access-Control-Allow-Origin, and Access-Control-Allow-Headers. The values of these will depend on your API.

如果您想向我发送您要调用的API资源,我可以从我们这边看一下.

If you'd like to send me the API resource you're trying to invoke, I can take a look from our side.

这篇关于带有Angular的AWS API Gateway的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆