如何将post请求成功发送到firebase函数

如何将post请求成功发送到firebase函数,firebase,google-cloud-firestore,google-cloud-functions,stripe-payments,angular-httpclient,Firebase,Google Cloud Firestore,Google Cloud Functions,Stripe Payments,Angular Httpclient,我一直在致力于在firebase托管函数中实现条带处理,但似乎无法使其正常工作。每当我从浏览器发送测试请求时,都会收到以下错误消息: 访问位于的XMLHttpRequest'https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel?database=projects%app-名称-a4da5%2F数据库%2F(默认)&VER=8&RID=73206&CVER=22&X-HTTP-Session-Id

我一直在致力于在firebase托管函数中实现条带处理,但似乎无法使其正常工作。每当我从浏览器发送测试请求时,都会收到以下错误消息:

访问位于的XMLHttpRequest'https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel?database=projects%app-名称-a4da5%2F数据库%2F(默认)&VER=8&RID=73206&CVER=22&X-HTTP-Session-Id=gsessionid&%24httpHeaders=Authorization%3ABearer%2tokent=1“来自源”http://localhost:8100'已被CORS策略阻止:当请求的凭据模式为'include'时,响应中的'Access Control Allow Origin'标头的值不得为通配符'*'。XMLHttpRequest启动的请求的凭据模式由withCredentials属性控制。
zone evergreen.js:2952 POSThttps://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel?database=projects%app-name-a4da5%2F数据库%2F(默认值)&VER=8&RID=7206&CVER=22&X-HTTP-Session-Id=gsessionid&%24httpHeaders=Authorization%3ABearer%token=1 net::ERR\u失败

Unchecked runtime.lastError:消息端口在收到响应之前关闭。
如HTTPS云函数中所述,您需要将代码封装在如下块中:

return cors(req, res, () => {
  // ...
});

因此,对于您的CF而言,以下各项应该有效(未经测试):

/。。。
const cors=require('cors')({origin:true});
// ...
exports.PayWithTripe=functions.https.onRequest((请求,响应)=>{
log('exports.payWithTripe=functions.https.onRequest',request);
返回cors(请求、响应,()=>{
stripe.charges.create({
金额:request.body.amount,
货币:request.body.currency,
来源:request.body.token,
})。然后((费用:任何)=>{
//异步调用
console.log(‘然后在收费之后’,收费);
响应。发送(收费);
})
.catch((错误:任意)=>{
console.log('来自费用的错误',err);
//!!在这里,您需要返回一个响应,如下所示!!!

response.status(500).send(err);//正如HTTPS云函数中所解释的,您需要将代码封装在如下块中:

return cors(req, res, () => {
  // ...
});

因此,对于您的CF而言,以下各项应该有效(未经测试):

/。。。
const cors=require('cors')({origin:true});
// ...
exports.PayWithTripe=functions.https.onRequest((请求,响应)=>{
log('exports.payWithTripe=functions.https.onRequest',request);
返回cors(请求、响应,()=>{
stripe.charges.create({
金额:request.body.amount,
货币:request.body.currency,
来源:request.body.token,
})。然后((费用:任何)=>{
//异步调用
console.log(‘然后在收费之后’,收费);
响应。发送(收费);
})
.catch((错误:任意)=>{
console.log('来自费用的错误',err);
//!!在这里,您需要返回一个响应,如下所示!!!

response.status(500).send(err);//您需要使用CORS支持适当地配置API服务器。您需要使用CORS支持适当地配置API服务器。