//native
type Fly = {
token: string;
};
/**
* Stop Machine
* Stop a specific Machine within an app, with an optional request body to specify signal and timeout.
*/
export async function main(
auth: Fly,
app_name: string,
machine_id: string,
body: { signal?: string; timeout?: { "time.Duration"?: number } },
) {
const url = new URL(
`https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}/stop`,
);
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.text();
}
Submitted by hugo697 235 days ago