Skip to content

hilja/fly-io-api

Repository files navigation

fly-io-api

TypeScript conduit to Fly.io machines API.

Install

pnpm add fly-io-api

Usage

Get machinesIds and do something with them:

import { Machine } from './index.ts'

const myApp = new Machine('my_app', process.env['FLY_API_TOKEN']!)

const stopped: string[] = []
for (const machine of await myApp.list()) {
  if (machine.state === 'stopped') stopped.push(machine.id)
}

console.log(`Starting machines: ${stopped.join(', ')}`)
await Promise.all(stopped.map(machineId => myApp.start({ machineId })))

The origin is set based on process.env.NODE_ENV, but you can have your own:

const origin =
  process.env['MY_ENV'] === 'live'
    ? 'http://_api.internal:4280'
    : 'https://api.machines.dev'

const myApp = new Machine('my_app', process.env['FLY_API_TOKEN']!, origin)

There's no real docs yet, but check index.ts, or the tests file index.test.ts. Or one of these resources:

Development

pnpm i
# Hack...
pnpm format
pnpm lint
pnpm test
pnpm build
pnpm ncu # Update packages

About

TypeScript conduit to Fly.io machines API

Resources

Stars

Watchers

Forks

Contributors