【发布时间】:2018-12-25 00:08:17
【问题描述】:
我想使用 Paypal 为我的市场设置付款。我使用 Angular 6 构建我的应用,使用 firebase 构建我的应用程序,使用 firebase 函数(谷歌云函数)。
我使用这个Paypal firebase function 示例来构建我的firebase 后端。
在我的前端应用程序中,我得到了这个函数来触发付款方式:
processPayment() {
this.http.post('https://us-central1-project.cloudfunctions.net/pay', {price: this.amount })
.subscribe(res => console.log(res));
}
所以这应该将我重定向到支付amount 变量的贝宝页面。这是 CORS 错误发生的地方,当我触发该函数时,我最终在控制台中出现此错误:
跨域请求被阻止:同源策略不允许读取位于https://us-central1-project.cloudfunctions.net/pay 的远程资源(原因:CORS 标头“Access-Control-Allow-Origin”缺失)。 跨域请求被阻止:同源策略不允许读取位于https://us-central1-project.cloudfunctions.net/pay 的远程资源。 (原因:CORS 请求未成功)。
如果我错了,请纠正我,但这个错误来自我试图通过 localhost:4200 使用我的 IP 访问此页面的事实。 (请注意,如果我手动向https://us-central1-cop-room-host.cloudfunctions.net/pay 发出请求,该页面正在工作)。
所以我尝试修改我的云功能代码,我补充道:
const cors = require('cors')({
origin: true,
});
但是,我最终在控制台中出现了这个错误:
跨域请求被阻止:同源策略不允许读取位于https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-54G25913XT5841335 的远程资源。 (原因:CORS 标头“Access-Control-Allow-Origin”缺失)。 跨域请求被阻止:同源策略不允许读取位于https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-54G25913XT5841335 的远程资源。 (原因:CORS 请求未成功)。
此外,origin:true 是不安全的......
如何配置此付款方式以使其与 angular 6 一起使用?
【问题讨论】:
标签: angular firebase paypal cors angular6