Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat: c.env()
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard committed Aug 16, 2023
1 parent 2676201 commit c15dd19
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ObjectType, Payload } from './handler.ts'
import { RequestContext } from './request_context.ts'
import { ResponseContext } from './response_context.ts'

type Variables = Record<string, unknown>

const HTTP_MESSAGES = {
'Bad Request': 400,
'Unauthorized': 401,
Expand Down Expand Up @@ -92,6 +94,10 @@ export class Context<
return this.runtime === 'deno' && Deno.env.get('DEV') === 'true'
}

env<T extends keyof Variables>(name: T): Variables[T] {
return this.runtime === 'cloudflare' ? (this.#a.env as Variables)[name] : Deno.env.get(name)
}

get req(): RequestContext<
Params,
ValidatedBody,
Expand Down

0 comments on commit c15dd19

Please sign in to comment.