@ alchemy. run/ fly
Fly.io 用于 炼金术。运行效果程序作为 Fly Services 和 Machines, 在管理 Postgres, Redis, 底格里斯桶和音量的旁边, 全部在一个 TypeScript 程序中 .
npm install alchemy @alchemy.run/fly effect
一个服务,计算访问雷迪斯:
// src/api.ts
import * as Fly from "@alchemy.run/fly";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
export const Cache = Fly.Redis("Cache");
export default class Api extends Fly.Service<Api>()(
"Api",
{ main: import.meta.url, region: "iad", port: 3000 },
Effect.gen(function* () {
const cache = yield* Fly.ReadWriteRedis(Cache);
return {
fetch: Effect.gen(function* () {
const visits = yield* cache.incr("visits");
return yield* HttpServerResponse.json({ visits });
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(Fly.ReadWriteRedisHttp)),
) {}
// alchemy.run.ts
import * as Alchemy from "alchemy";
import * as Fly from "@alchemy.run/fly";
import * as Effect from "effect/Effect";
import Api from "./src/api.ts";
export default Alchemy.Stack(
"MyApp",
{
providers: Fly.providers(),
state: Alchemy.localState(),
},
Effect.gen(function* () {
const api = yield* Api;
return { url: api.url };
}),
);
alchemy deploy 构建图像,创建应用程序及其机器,以及提供Redis. 你从不写 Docker 文件或文件 fly.toml。 。 。 .