Skip to content

Commit

Permalink
add HttpServer.layerContext to platform-node/bun
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Oct 21, 2024
1 parent 6734a03 commit ec8c546
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/three-horses-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effect/platform-node": patch
"@effect/platform-bun": patch
"@effect/platform": patch
---

add HttpServer.layerContext to platform-node/bun
16 changes: 16 additions & 0 deletions packages/platform-bun/src/BunHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,19 @@ export const layerConfig: (
Server.HttpServer | Platform.HttpPlatform | Etag.Generator | BunContext.BunContext,
ConfigError.ConfigError
> = internal.layerConfig

/**
* A Layer providing the `HttpPlatform`, `FileSystem`, `Etag.Generator`, and `Path`
* services.
*
* The `FileSystem` service is a no-op implementation, so this layer is only
* useful for platforms that have no file system.
*
* @since 1.0.0
* @category layers
*/
export const layerContext: Layer.Layer<
| Platform.HttpPlatform
| Etag.Generator
| BunContext.BunContext
> = internal.layerContext
15 changes: 9 additions & 6 deletions packages/platform-bun/src/internal/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ export const layer = (
) =>
Layer.mergeAll(
Layer.scoped(Server.HttpServer, make(options)),
Platform.layer,
Etag.layerWeak,
BunContext.layer
layerContext
)

/** @internal */
Expand All @@ -192,11 +190,16 @@ export const layerConfig = (
) =>
Layer.mergeAll(
Layer.scoped(Server.HttpServer, Effect.flatMap(Config.unwrap(options), make)),
Platform.layer,
Etag.layerWeak,
BunContext.layer
layerContext
)

/** @internal */
export const layerContext = Layer.mergeAll(
Platform.layer,
Etag.layerWeak,
BunContext.layer
)

interface WebSocketContext {
readonly deferred: Deferred.Deferred<ServerWebSocket<WebSocketContext>>
readonly closeDeferred: Deferred.Deferred<void, Socket.SocketError>
Expand Down
16 changes: 16 additions & 0 deletions packages/platform-node/src/NodeHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,19 @@ export const layerTest: Layer.Layer<
| NodeContext.NodeContext,
ServeError
> = internal.layerTest

/**
* A Layer providing the `HttpPlatform`, `FileSystem`, `Etag.Generator`, and `Path`
* services.
*
* The `FileSystem` service is a no-op implementation, so this layer is only
* useful for platforms that have no file system.
*
* @since 1.0.0
* @category layers
*/
export const layerContext: Layer.Layer<
| Platform.HttpPlatform
| Etag.Generator
| NodeContext.NodeContext
> = internal.layerContext
11 changes: 8 additions & 3 deletions packages/platform-node/src/internal/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,16 @@ export const layer = (
) =>
Layer.mergeAll(
Layer.scoped(Server.HttpServer, make(evaluate, options)),
internalPlatform.layer,
Etag.layerWeak,
NodeContext.layer
layerContext
)

/** @internal */
export const layerContext = Layer.mergeAll(
internalPlatform.layer,
Etag.layerWeak,
NodeContext.layer
)

/** @internal */
export const layerTest = Server.layerTestClient.pipe(
Layer.provide(NodeHttpClient.layerWithoutAgent),
Expand Down
2 changes: 2 additions & 0 deletions packages/platform/src/HttpApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export const httpApp: Effect.Effect<
* const { dispose, handler } = HttpApiBuilder.toWebHandler(
* Layer.mergeAll(
* MyApiLive,
* // you could also use NodeHttpServer.layerContext, depending on your
* // server's platform
* HttpServer.layerContext
* )
* )
Expand Down

0 comments on commit ec8c546

Please sign in to comment.