magne4000 / universal-middleware

Write middleware once, target Hono, Cloudflare, Express, and more
https://universal-middleware.dev/
MIT License
28 stars 1 forks source link

feat: add env() helper #32

Closed magne4000 closed 2 months ago

magne4000 commented 2 months ago

Closes #30

Usage

import { env, type Get, type UniversalMiddleware } from "@universal-middleware/core";

const handler = (() => (request, context, runtime) => {
  // process.env.DATABASE_URL on supported environment
  // Done.env.get("DATABASE_URL") for Deno
  // runtime.env.DATABASE_URL for Cloudflare
  const { DATABASE_URL } = env<{ DATABASE_URL: string }>(runtime);

  // ...
}) satisfies Get<[], UniversalMiddleware>;