Loading Runtime Values in Config Provider

Hi! I'm trying to find the right pattern to load values that are available at runtime only into my config provider layer. This constraint comes from Cloudflare Workers. Here is a snippet how how I'm doing it right now, but this causes a "Disallowed operation called within global scope" because I'm loading from env outside a fetch request handler execution.
import { env } from "cloudflare:workers";

export const ConfigLive = () => Layer.setConfigProvider(
  ConfigProvider.fromMap(
    new Map([["DATABASE_URL", env.HYPERDRIVE.connectionString]])
  )
);

Any tips? Thanks for your time
Was this page helpful?