1 回答
TA贡献1811条经验 获得超5个赞
我添加了cors package:
const cors = require('cors')({origin: true});
然后,我在函数内部使用了 CORS 中间件。所以,最终的解决方案是:
const functions = require('firebase-functions');
const cors = require('cors')({origin: true});
const stripe = require("stripe")("PRIVATE_KEY");
exports.chargeStripe = functions.https.onRequest( (request, response) => {
// Enable CORS using the `cors` express middleware.
return cors(request, response, async () => {
// Reading token
let token = request.body.stripeToken;
// Charging user
let charge = await stripe.charges.create({
amount: 99,
currency: 'eur',
description: 'Payment',
source: token
});
// Sending response
response.status(200).send('Ok');
});
});
添加回答
举报