[英]Error when I deploy cloud function Firebase/Stripe
this is the first time I try to deploy cloud function in Firebase, usually I use Direbase emulator, but in this case, using Stripe, I am having problems with Cors. When I run the command: firebase deploy --only functions
, I have no compilation errors, but it tells me that there were errors during the release.这是我第一次尝试在 Firebase 中部署云 function,通常我使用 Direbase 模拟器,但在这种情况下,使用 Stripe,我遇到了 Cors 的问题。当我运行命令时:
firebase deploy --only functions
,我有没有编译错误,但它告诉我在发布期间有错误。 Seeing from the Firebase console, I notice that in the logs, it says:从 Firebase 控制台看,我注意到在日志中,它说:
"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Function failed on loading user code.
"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"函数加载用户代码失败。
This is my cloud function, I don't understand the error what is:这是我的云function,我不明白错误是什么:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const stripe = require("stripe")(functions.config().stripe.secret_key);
admin.initializeApp(functions.config().firebase);
export const createCheckoutSessionGreen = functions.region("europe-west6")
.https.onCall(
async (data: any, context: any) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "payment",
success_url: "http://localhost:8100/tabs/types/song",
cancel_url: "http://localhost:8100/tabs/types/song",
line_items: [
{
price_data: {
currency: "eur",
product_data: {
name: data,
},
unit_amount: 1.99 * 100,
},
quantity: 1,
},
],
});
return session.id;
}
);
You need to use Typescript with Cloud Function if you want to use the ES6
syntax.如果要使用
ES6
语法,则需要使用 Typescript 和 Cloud Function。 It seems you are using Javascript so try refactoring the code using exports
instead of export const
.看来您正在使用 Javascript 所以尝试使用
exports
而不是export const
重构代码。 Also you don't need to pass any parameters to initializeApp()
since you are deploying to Cloud Functions which will then use Application Default Credentials :此外,您不需要将任何参数传递给
initializeApp()
,因为您正在部署到 Cloud Functions,后者将使用应用程序默认凭证:
admin.initializeApp();
exports.createCheckoutSessionGreen = functions.region("europe-west6").https.onCall(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.