我有一个AWS API网关,它接受一个POST请求来触发Lambda函数并返回结果。
我尝试在API上启用CORS。
const url = 'XXX'
@inject(HttpClient)
export class App {
constructor(http) {
http.configure(config =>
config
.useStandardConfiguration()
.withBaseUrl(url)
.withDefaults({
// mode: 'no-cors',
headers: {
'Content-type' : 'application/json'
}
}));
this.http = http;
this.http.fetch('/', { method: 'post', body: {data: 'XXXX'} })
.then(res => res.json())
.then(console.log)
.catch(console.error)
}
结果是:
body:null
bodyUsed:false
headers:Headers
ok:false
status:0
statusText:""
type:"opaque"
url:""
我试过了:
我甚至尝试将Lambda函数更改为:
exports.handler = function(event, context, callback) {
callback(null, {"success": true});
}
确保lambda函数"工作" (它在Cloudwatch中看到了)
答案 0 :(得分:0)
您不需要在Aurelia http中启用CORS,因为Aurelia Fetch客户端的默认设置是CORS。我会说你的AWS API网关问题是99%。您是否尝试从其他应用程序获取端点? (例如使用Postman chrome扩展)。它有效吗?