Back

[Error]: connect ECONNREFUSED 127.0.1.1:443 - function to create a Team

  • 0
  • Self Hosted
  • Functions
  • Web
  • Auth
Dan
14 Mar, 2024, 18:30

Using Appwrite 1.5.3 and Next.js 14 App Router. I'm having a problem trying to create a Team for a user. I have an ./app/api/stripeWebhook/route.ts file, which watches for the checkout.session.completed Stripe webhook. Attached for context.

The following within the file is executing a serverless function:

TypeScript
const executionTeam = await functions.createExecution(
        process.env.APPWRITE_FUNCTION_ID_CREATE_SUBDOMAIN_TEAM!,
        JSON.stringify(data),
        false
      );

The serverless function includes a file ./functions/createSubdomainTeam/src/main.js shared below:

TypeScript
import { Client, Teams, ID } from "node-appwrite";

function formatSubdomain(subdomain) {
  // omitted for brevity
}

export default async function (event) {
  const client = new Client();
  const teams = new Teams(client);

  client
    .setEndpoint(process.env.APPWRITE_ENDPOINT)
    .setProject(process.env.APPWRITE_PROJECT_ID)
    .setKey(process.env.APPWRITE_API_KEY_CREATE_SUBDOMAIN_TEAM);

  let payload;
  try {
    payload = JSON.parse(event.req.bodyRaw || "{}");
  } catch (error) {
    // omitted for brevity
    return { error: "Error parsing payload" };
  }

  const subdomain = payload.subdomain || "";

  if (!subdomain) {
    // omitted for brevity
  }

  const formattedSubdomain = formatSubdomain(subdomain);

  try {
    const team = await teams.create(ID.unique(), formattedSubdomain, [
      "host",
      "guest",
    ]);

    return { success: true, teamId: team.$id };
  } catch (error) {
    // omitted for brevity
  }
}

The createSubdomainTeam Function is executed with a 200 code, but the Response logs return the following and no Team is created. Any help would be appreciated

TypeScript
Failed to create subdomain team and add user: AppwriteException [Error]: connect ECONNREFUSED 127.0.1.1:443
    at Client.call (/usr/local/server/src/function/node_modules/node-appwrite/lib/client.js:180:23) {
  code: undefined,
  type: undefined,
  response: undefined
}
TL;DR
Developers encountering 127.0.1.1:443 connection error when creating a Team with Appwrite and Next.js. Solution involves checking Appwrite endpoint settings and ensuring proper API key, project ID, and endpoint are configured in the serverless function.
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