// src/implementation.ts
import { HttpApiBuilder, HttpApiSwagger } from '@effect/platform'
import { BunHttpServer, BunRuntime } from '@effect/platform-bun'
import { Effect, Layer } from 'effect'
import { api } from './contract.ts'
// Implement the "Greetings" group
const GreetingsLive = HttpApiBuilder.group(api, 'Greetings', (handlers) =>
handlers.handle('hello', () => Effect.succeed({ message: 'Hello from Effect on Cloudflare!' })),
)
// Create the final, implemented API Layer
export const MyApiLive = HttpApiBuilder.api(api).pipe(
Layer.provide(HttpApiSwagger.layer()),
Layer.provide(GreetingsLive),
)
// Set up the server using BunHttpServer on port 3000
const ServerLive = HttpApiBuilder.serve().pipe(
Layer.provide(MyApiLive),
Layer.provide(BunHttpServer.layer({ port: 3000 })),
)
// Launch the server
// Error v
Layer.launch(ServerLive).pipe(BunRuntime.runMain)
// src/implementation.ts
import { HttpApiBuilder, HttpApiSwagger } from '@effect/platform'
import { BunHttpServer, BunRuntime } from '@effect/platform-bun'
import { Effect, Layer } from 'effect'
import { api } from './contract.ts'
// Implement the "Greetings" group
const GreetingsLive = HttpApiBuilder.group(api, 'Greetings', (handlers) =>
handlers.handle('hello', () => Effect.succeed({ message: 'Hello from Effect on Cloudflare!' })),
)
// Create the final, implemented API Layer
export const MyApiLive = HttpApiBuilder.api(api).pipe(
Layer.provide(HttpApiSwagger.layer()),
Layer.provide(GreetingsLive),
)
// Set up the server using BunHttpServer on port 3000
const ServerLive = HttpApiBuilder.serve().pipe(
Layer.provide(MyApiLive),
Layer.provide(BunHttpServer.layer({ port: 3000 })),
)
// Launch the server
// Error v
Layer.launch(ServerLive).pipe(BunRuntime.runMain)