-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcustom-response.ts
More file actions
32 lines (28 loc) · 829 Bytes
/
custom-response.ts
File metadata and controls
32 lines (28 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { NodeRuntime } from "@effect/platform-node"
import { Effect, Logger, LogLevel, pipe, Schema } from "effect"
import { Api, RouterBuilder } from "effect-http"
import { NodeServer } from "effect-http-node"
const api = Api.make().pipe(
Api.addEndpoint(
Api.get("hello", "/hello").pipe(
Api.setResponseStatus(201),
Api.setResponseBody(Schema.Number),
Api.setResponseHeaders(Schema.Struct({ "x-hello-world": Schema.String }))
)
)
)
const app = pipe(
RouterBuilder.make(api),
RouterBuilder.handle(
"hello",
() => Effect.succeed({ body: 12, headers: { "x-hello-world": "test" }, status: 201 as const })
),
RouterBuilder.build
)
pipe(
app,
NodeServer.listen({ port: 3000 }),
Effect.provide(Logger.pretty),
Logger.withMinimumLogLevel(LogLevel.All),
NodeRuntime.runMain
)