-
-
Notifications
You must be signed in to change notification settings - Fork 458
/
adapter.ts
34 lines (32 loc) · 853 Bytes
/
adapter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { Context } from './context.ts'
export const env = <T = Record<string, string>>(c: Context): T => {
// 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 === 'fastly') {
let env = {}
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const data = require('fastly:env')
env = data.env
} catch {}
return env as T
}
if (c.runtime === 'workerd') {
return c.env
}
return {} as T
}