Skip to content
Myr

fetch.ts

This file

Path

apps/platform/src/adapters/fetch.ts

29 lines · 909 bytes · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–6why, one step back
1import { Fetch, FetchFailed } from "@repo/artifacts/fetch";
2import { Effect, Layer } from "effect";34// @effect-diagnostics globalFetch:off -- the Worker's fetch is the one HTTP client; every caller goes through this port5const send = (request: Request) => fetch(request);6

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

line 7why, one step back
7// Origin and path only, so no credential travels in a failure's text.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 8–29why, one step back
8const placeOf = (request: Request) => {
9 const url = new URL(request.url);1011 return `${url.origin}${url.pathname}`;12};1314const reasonOf = (cause: unknown) =>15 cause instanceof Error16 ? `the request got no response: ${cause.name}`17 : "the request got no response";1819export const WorkerFetch: Layer.Layer<Fetch> = Layer.succeed(20 Fetch,21 Fetch.of({22 fetch: (request) =>23 Effect.tryPromise({24 catch: (cause) =>25 new FetchFailed({ reason: reasonOf(cause), url: placeOf(request) }),26 try: () => send(request),27 }),28 })29);