The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | # @alchemy.run/fly |
| 2 | |
| 3 | Fly.io for [Alchemy](https://alchemy.run). Run Effect programs as Fly Services and Machines, next to Managed Postgres, Redis, Tigris buckets, and volumes, all in one TypeScript program. |
| 4 | |
| 5 | ```sh |
| 6 | npm install alchemy @alchemy.run/fly effect |
| 7 | ``` |
| 8 | |
| 9 | A Service that counts visits in Redis: |
| 10 | |
| 11 | ```typescript |
| 12 | // src/api.ts |
| 13 | import * as Fly from "@alchemy.run/fly"; |
| 14 | import * as Effect from "effect/Effect"; |
| 15 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 16 | |
| 17 | export const Cache = Fly.Redis("Cache"); |
| 18 | |
| 19 | export default class Api extends Fly.Service<Api>()( |
| 20 | "Api", |
| 21 | { main: import.meta.url, region: "iad", port: 3000 }, |
| 22 | Effect.gen(function* () { |
| 23 | const cache = yield* Fly.ReadWriteRedis(Cache); |
| 24 | |
| 25 | return { |
| 26 | fetch: Effect.gen(function* () { |
| 27 | const visits = yield* cache.incr("visits"); |
| 28 | return yield* HttpServerResponse.json({ visits }); |
| 29 | }).pipe(Effect.orDie), |
| 30 | }; |
| 31 | }).pipe(Effect.provide(Fly.ReadWriteRedisHttp)), |
| 32 | ) {} |
| 33 | ``` |
| 34 | |
| 35 | ```typescript |
| 36 | // alchemy.run.ts |
| 37 | import * as Alchemy from "alchemy"; |
| 38 | import * as Fly from "@alchemy.run/fly"; |
| 39 | import * as Effect from "effect/Effect"; |
| 40 | import Api from "./src/api.ts"; |
| 41 | |
| 42 | export default Alchemy.Stack( |
| 43 | "MyApp", |
| 44 | { |
| 45 | providers: Fly.providers(), |
| 46 | state: Alchemy.localState(), |
| 47 | }, |
| 48 | Effect.gen(function* () { |
| 49 | const api = yield* Api; |
| 50 | return { url: api.url }; |
| 51 | }), |
| 52 | ); |
| 53 | ``` |
| 54 | |
| 55 | `alchemy deploy` builds the image, creates the app and its Machines, and provisions Redis. You never write a Dockerfile or a `fly.toml`. |
| 56 | |
| 57 | ## Learn more |
| 58 | |
| 59 | - [Fly.io on alchemy.run](https://alchemy.run/fly) |
| 60 | - [Setup](https://alchemy.run/fly/setup) |
| 61 | - [Tutorial](https://alchemy.run/fly/tutorial/part-1) |
| 62 | - [API reference](https://alchemy.run/providers) |