Edits history of script submission #15851 for ' Execute Command (fly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Fly = {
      token: string;
    };
    /**
     * Execute Command
     * Execute a command on a specific Machine and return the raw command output bytes.
    
     */
    export async function main(
      auth: Fly,
      app_name: string,
      machine_id: string,
      body: {
        cmd?: string;
        command?: string[];
        container?: string;
        stdin?: string;
        timeout?: number;
      },
    ) {
      const url = new URL(
        `https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}/exec`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago