Back

Can not see node-18 runtime when init function using appwrite-cli

  • 0
  • Tools
  • Functions
kaliz
17 Mar, 2023, 02:54

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

TypeScript
Node.js (node-16.0)
PHP (php-8.0)
Ruby (ruby-3.0)
Python (python-3.9)
TypeScript
appwrite -v
1.2.1
TL;DR
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
17 Mar, 2023, 02:54

Can not see node-18 runtime when init function using appwrite-cli

Drake
17 Mar, 2023, 02:55
kaliz
17 Mar, 2023, 03:17

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
17 Mar, 2023, 03:20

What's your full code?

kaliz
17 Mar, 2023, 03:24
TypeScript
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;
   
  }
kaliz
17 Mar, 2023, 03:24
TypeScript
module.exports = async function (req, res) {
  // const payload = JSON.parse(req.payload);
  // if (!payload.productId || !payload.token){
  //   console.log("No payload");
  //   res.json({status: '1'});
  // }
  const productData = productDataMap["soundwave_pro"];
  // if (!productData) {
  //   console.log("No productData");
  //   res.json({status: '2'});
  // }
  const data = await handleSubscription(productData,"thisisfixedtoken");
  if (!data){
    res.json({status: '3'});
  }
};
kaliz
17 Mar, 2023, 03:26

My project structure

kaliz
17 Mar, 2023, 03:27

How can I check why this code timeout

Drake
17 Mar, 2023, 03:27

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
17 Mar, 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
17 Mar, 2023, 03:30

This code from codelabs tutorial and I run successful in local node server

Drake
17 Mar, 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

kaliz
17 Mar, 2023, 03:36

Thank you for help

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more