Release 202506041641
This commit is contained in:
14
web/src/lib/serverEnvVariables.ts
Normal file
14
web/src/lib/serverEnvVariables.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { loadEnv } from 'vite'
|
||||
|
||||
/** Only use when you can't import the variables from `astro:env/server` */
|
||||
// @ts-expect-error process.env actually exists
|
||||
const untypedServerEnvVariables = loadEnv(process.env.NODE_ENV, process.cwd(), '')
|
||||
|
||||
/** Only use when you can't import the variables from `astro:env/server` */
|
||||
export function getServerEnvVariable<T extends keyof typeof untypedServerEnvVariables>(
|
||||
name: T
|
||||
): NonNullable<(typeof untypedServerEnvVariables)[T]> {
|
||||
const value = untypedServerEnvVariables[name]
|
||||
if (!value) throw new Error(`${name} environment variable is not set`)
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user