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

feat: c.env() #173

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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,12 @@ export class Context<
return this.runtime === 'deno' && Deno.env.get('DEV') === 'true'
}

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

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