How can I choose node-18 runtime when using appwrite-cli to init function?
My appwrite-cli only display this:
I'm use latest docker version of appwrite: appwrite/appwrite:1.2.1
The user is experiencing a timeout error when deploying a function in the Appwrite CLI. They are trying to verify a purchase using the Google API, and the code works fine on their local server. They are seeking help to troubleshoot the error and discover why the code is timing out.
Potential solutions:
1. Recreate the function from scratch, starting with the imports.
2. Ensure that `res.json()` is only called once in the code.
3. Check the project structure and make necessary adjustments.
4. Consider checking the Appwrite GitHub discussions for assistance.
Regarding the second part of the thread, the
kaliz
Rank 2: Process
Mar 17, 2023, 02:54
Can not see node-18 runtime when init function using appwrite-cli
I deploy my first function but get time out. My code is try to verify purchase using googleapi. This code work fine in my local node server. How can I inspect to fix this error
Drake
Admin
Mar 17, 2023, 03:20
What's your full code?
kaliz
Rank 2: Process
Mar 17, 2023, 03:24
const {GoogleAuth} = require("google-auth-library");
const {androidpublisher_v3} =require("googleapis");
const credentials = require("./assets/service-account.json");
const {ANDROID_PACKAGE_ID, productDataMap} = require("./constants");
const handleSubscription = async(
productData,
token,
) => {
var androidPublisher = new androidpublisher_v3.Androidpublisher({
auth: new GoogleAuth(
{
credentials,
scopes: ["https://www.googleapis.com/auth/androidpublisher"],
}),
});
let response;
try {
response = await androidPublisher.purchases.subscriptions.get(
{
packageName: ANDROID_PACKAGE_ID,
subscriptionId: productData.productId,
token,
},
);
} catch (err){
throw err;
}
// Make sure an order id exists
if (!response.data.orderId) {
return false;
}
// If a subscription suffix is present (..#) extract the orderId.
let orderId = response.data.orderId;
const orderIdMatch = /^(.+)?[.]{2}[0-9]+$/g.exec(orderId);
if (orderIdMatch) {
orderId = orderIdMatch[1];
}
console.log({
rawOrderId: response.data.orderId,
newOrderId: orderId,
});
// Construct purchase data for db updates
const purchaseData = {
type: "SUBSCRIPTION",
iapSource: "google_play",
orderId: orderId,
productId: productData.productId,
purchaseDate: response.data.startTimeMillis ?? 0,
expiryDate: response.data.expiryTimeMillis ?? 0,
status: [
"PENDING", // Payment pending
"ACTIVE", // Payment received
"ACTIVE", // Free trial
"PENDING", // Pending deferred upgrade/downgrade
"EXPIRED", // Expired or cancelled
][response.data.paymentState ?? 4],
};
return purchaseData;
}
You should make sure you're calling res.json() exactly once. It seems like it's possible for you to not based on this code.
Drake
Admin
Mar 17, 2023, 03:30
Although connection refused is an even bigger problem ..it might mean the runtime container isn't working at all. Maybe syntax problem or something.
kaliz
Rank 2: Process
Mar 17, 2023, 03:30
This code from codelabs tutorial and I run successful in local node server
Drake
Admin
Mar 17, 2023, 03:32
Regardless, something might be wrong in the runtime. I would recommend recreating your function from scratch adding bits slowly, starting with the imports