Getting function url for localhost emulator setup firebase

29 Views Asked by At

I want to access my function url from localhost to use it with taskQueue.

I wrote the function like this but that is trying to access function on firebase i dont know how to setup localhost url.

export async function getFunctionUrl(name: string, location = "us-central1") {
  const auth = new GoogleAuth({
    scopes: "https://www.googleapis.com/auth/cloud-platform"
  });
  const projectId = await auth.getProjectId();

  const baseUrl = "https://cloudfunctions.googleapis.com";
  const url = `${baseUrl}/v2beta/projects/${projectId}/locations/${location}/functions/${name}`;

  const client = await auth.getClient();
  const res = await client.request<any>({ url });
  const uri = res.data?.serviceConfig?.uri;
  if (!uri) {
    throw new Error(`Unable to retreive uri for function at ${url}`);
  }
  logger.log("Function URL for Task:", name, uri);
  return uri;
};

I have also tried to get it like this http://127.0.0.1:5001/myproject-dev/us-central1/myfunction

0

There are 0 best solutions below