0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-30 01:56:18 +01:00
hono/deno_dist/adapter.ts
Yusuke Wada 85528398c3
fix: check global.fastly instead of require('fastly:env') (#1057)
* fix: use `global.fastly` instead of `require('fastly:env')`

* denoify
2023-05-02 16:26:39 +09:00

31 lines
796 B
TypeScript

import type { Context } from './context.ts'
export const env = <T extends Record<string, string>, C extends Context = Context<{}>>(
c: C
): T & C['env'] => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const global = globalThis as any
if (
c.runtime === 'bun' ||
c.runtime === 'node' ||
c.runtime === 'edge-light' ||
c.runtime === 'lagon'
) {
return global?.process?.env as T
}
if (c.runtime === 'deno') {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return Deno.env.toObject()
}
if (c.runtime === 'workerd') {
return c.env
}
if (c.runtime === 'fastly') {
// On Fastly Compute@Edge, you can use the ConfigStore to manage user-defined data.
return {} as T
}
return {} as T
}