Skip to content

Commit 081f4d8

Browse files
authored
add platform literal to HttpPlatform (#6723)
1 parent 35141f1 commit 081f4d8

6 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎.changeset/clever-maps-care.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@effect/platform-deno": patch
3+
"@effect/platform-node": patch
4+
"@effect/platform-bun": patch
5+
"effect": patch
6+
---
7+
8+
add platform literal to HttpPlatform

‎packages/effect/src/unstable/http/HttpPlatform.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import * as Response from "./HttpServerResponse.ts"
2929
* @since 4.0.0
3030
*/
3131
export class HttpPlatform extends Context.Service<HttpPlatform, {
32+
readonly platform: "deno" | "node" | "bun" | "web"
3233
readonly fileResponse: (
3334
path: string,
3435
options?: Response.Options.WithContent & {
@@ -54,6 +55,7 @@ export class HttpPlatform extends Context.Service<HttpPlatform, {
5455
* @since 4.0.0
5556
*/
5657
export const make: (impl: {
58+
readonly platform: "deno" | "node" | "bun" | "web"
5759
readonly fileResponse: (
5860
path: string,
5961
status: number,
@@ -83,6 +85,7 @@ export const make: (impl: {
8385
const etagGen = yield* Etag.Generator
8486

8587
return HttpPlatform.of({
88+
platform: impl.platform,
8689
fileResponse: Effect.fnUntraced(function*(path, options) {
8790
const info = yield* fs.stat(path)
8891
const etag = yield* etagGen.fromFileInfo(info)
@@ -143,6 +146,7 @@ export const make: (impl: {
143146
export const layer = Layer.effect(HttpPlatform)(
144147
Effect.flatMap(FileSystem.FileSystem, (fs) =>
145148
make({
149+
platform: "web",
146150
fileResponse(path, status, statusText, headers, start, end, contentLength) {
147151
return Response.stream(
148152
fs.stream(path, {

‎packages/platform-bun/src/BunHttpPlatform.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const make: Effect.Effect<
2626
never,
2727
FileSystem | Etag.Generator
2828
> = Platform.make({
29+
platform: "bun",
2930
fileResponse(path, status, statusText, headers, start, end, _contentLength) {
3031
let file = Bun.file(path)
3132
if (start > 0 || end !== undefined) {

‎packages/platform-deno/src/DenoHttpPlatform.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import * as DenoFileSystem from "./DenoFileSystem.ts"
2828
* @since 4.0.0
2929
*/
3030
export const make = Platform.make({
31+
platform: "deno",
3132
fileResponse(path, status, statusText, headers, start, end, contentLength) {
3233
let body: ReadableStream<Uint8Array>
3334
if (contentLength === 0) {

‎packages/platform-node/src/NodeHttpPlatform.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import * as NodeFileSystem from "./NodeFileSystem.ts"
2727
* @since 4.0.0
2828
*/
2929
export const make = Platform.make({
30+
platform: "node",
3031
fileResponse(path, status, statusText, headers, start, end, contentLength) {
3132
const stream = contentLength === 0
3233
? Readable.from([])

‎packages/platform-node/test/HttpStaticServerConditional.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const makeHandler = async () => {
6161
})
6262

6363
const httpPlatform = HttpPlatform.HttpPlatform.of({
64+
platform: "node",
6465
fileResponse: (_path, options) =>
6566
Effect.succeed(HttpServerResponse.text(fileBody, {
6667
status: options?.status,
@@ -100,6 +101,7 @@ const makeFailingApp = async (options: {
100101
})
101102

102103
const httpPlatform = HttpPlatform.HttpPlatform.of({
104+
platform: "node",
103105
fileResponse: (_path, fileOptions) => {
104106
if (options.fileResponseError !== undefined) {
105107
return Effect.fail(options.fileResponseError)
@@ -137,6 +139,7 @@ const makeLayerHandler = (options: {
137139
}
138140
})
139141
const httpPlatform = HttpPlatform.HttpPlatform.of({
142+
platform: "node",
140143
fileResponse: () =>
141144
options.fileResponseError !== undefined
142145
? Effect.fail(options.fileResponseError)

0 commit comments

Comments
 (0)