Edits history of script submission #10946 for ' Restart an App (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Restart an App
     * Perform a rolling restart of all or specific components in an app.
     */
    export async function main(
      auth: Digitalocean,
      app_id: string,
      body: { components?: string[] },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/apps/${app_id}/restart`);
    
      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 537 days ago