Skip to content

Commit 83134d6

Browse files
authored
fix: use process.env if context.env isn't defined in hono (#92)
It looks like context.env is only defined in Cloudflare Workers. https://hono.dev/docs/api/context#env When the serve method from hono is used in vercel, context.env is undefined which causes an error. Fixed the issue by checking if context.env is defined and falling back to process.env if it isn't. Fixes: #91
1 parent ad2eafc commit 83134d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

platforms/hono.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export const serve = <
3737
options?: PublicServeOptions<TInitialPayload>
3838
): ((context: Context<{ Bindings: TBindings; Variables: TVariables }>) => Promise<Response>) => {
3939
const handler = async (context: Context<{ Bindings: TBindings; Variables: TVariables }>) => {
40-
const environment = context.env;
40+
const environment = context.env
41+
? context.env
42+
: typeof process === "undefined"
43+
? ({} as Record<string, string>)
44+
: process.env;
4145
const request = context.req.raw;
4246

4347
const { handler: serveHandler } = serveBase(routeFunction, telemetry, {

0 commit comments

Comments
 (0)