Creating a Baseline HTTP Client with Dependency Injection in TypeScript

for the life of me im trying to create a baseline http client i can inject to all other services. its meant to have a hase url and a auth bearer token from a cache, havn't got that far yet on account of it just refusing to work...

// http.live.ts
import { HttpClient, HttpClientRequest } from "@effect/platform";
import { Config, Effect } from "effect";

export const makeHttpClient = Effect.gen(function* () {
  const baseURL = yield* Config.string("BASE_PATH");
  const defaultClient = yield* HttpClient.HttpClient;

  return defaultClient.pipe(HttpClient.mapRequest(HttpClientRequest.prependUrl(baseURL)));
});

// http.client.ts
import * as Platform from "@effect/platform";
import { Context, Layer } from "effect";
import { makeHttpClient } from "./http.live";

export class HttpClient extends Context.Tag("@app/http-client")<
  HttpClient,
  Platform.HttpClient.HttpClient.Service
>() {
  static Layer = Layer.effect(HttpClient, makeHttpClient);
  static Live = Layer.provide(HttpClient.Layer, Platform.FetchHttpClient.layer);
}

// runtime.ts
export const AppLayer = Layer.mergeAll(NodeFileSystem.layer, Path.layer, HttpClient.Live);


everything i try and do i get hit with the following when attempting to yield my HttpClient into an effect...

[vite] Internal server error: Cannot read properties of undefined (reading 'Live')


any help would be greatly appreciated...
Was this page helpful?