Skip to content

Commit

Permalink
Add missing listen example for Bun (#4383)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatakeshi authored Feb 1, 2025
1 parent dedadf1 commit fd92e69
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,8 @@ timestamp=... level=INFO fiber=#0 message="Listening on http://localhost:3000"

To avoid boilerplate code for the final server setup, we'll use a helper function from the `listen.ts` file:

Node.js Example

```ts
import type { HttpPlatform, HttpServer } from "@effect/platform"
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node"
Expand All @@ -3390,6 +3392,31 @@ export const listen = (
)
```

Bun Example

```ts
import type { HttpPlatform, HttpServer } from "@effect/platform"
import { BunHttpServer, BunRuntime } from "@effect/platform-bun"
import { Layer } from "effect"

export const listen = (
app: Layer.Layer<
never,
never,
HttpPlatform.HttpPlatform | HttpServer.HttpServer
>,
port: number
) =>
BunRuntime.runMain(
Layer.launch(
Layer.provide(
app,
BunHttpServer.layer({ port })
)
)
)
```

### Basic routing

Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on).
Expand Down

0 comments on commit fd92e69

Please sign in to comment.