| 1 | import * as Cloudflare from "alchemy/Cloudflare"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FileSystem from "effect/FileSystem"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as Path from "effect/Path"; |
| 6 | import * as Etag from "effect/http/Etag"; |
| 7 | import * as HttpPlatform from "effect/http/HttpPlatform"; |
| 8 | import * as HttpRouter from "effect/http/HttpRouter"; |
| 9 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 10 | import { BackendApi } from "./BackendApi"; |
| 11 | import { BackendHandlers } from "./BackendHandlers"; |
| 12 | |
| 13 | const platformLayer = Layer.mergeAll( |
| 14 | Etag.layer, |
| 15 | HttpPlatform.layer.pipe(Layer.provide(FileSystem.layerNoop({}))), |
| 16 | FileSystem.layerNoop({}), |
| 17 | Path.layer, |
| 18 | ); |
| 19 | |
| 20 | export default class Backend extends Cloudflare.Worker<Backend>()( |
| 21 | "Backend", |
| 22 | { |
| 23 | main: import.meta.url, |
| 24 | dev: { port: 1338 }, |
| 25 | compatibility: { |
| 26 | date: "2026-03-17", |
| 27 | flags: ["nodejs_compat"], |
| 28 | }, |
| 29 | }, |
| 30 | Effect.gen(function* () { |
| 31 | return { |
| 32 | fetch: yield* HttpApiBuilder.layer(BackendApi).pipe( |
| 33 | Layer.provide(BackendHandlers), |
| 34 | Layer.provide(platformLayer), |
| 35 | HttpRouter.toHttpEffect, |
| 36 | ), |
| 37 | }; |
| 38 | }).pipe(Effect.provide(Cloudflare.D1.QueryDatabaseBinding)), |
| 39 | ) {} |