mirror of
https://github.com/nestriness/nestri.git
synced 2026-09-20 01:35:19 +03:00
feat: Sync to OSS repo
This commit is contained in:
41
packages/core/src/env.ts
Normal file
41
packages/core/src/env.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { memo } from './utils/memo.js';
|
||||
|
||||
let _overrides: Record<string, unknown> = {};
|
||||
|
||||
export namespace Env {
|
||||
export const Info = z.object({
|
||||
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
||||
|
||||
STEAM_API_KEY: z.string().optional(),
|
||||
|
||||
AUTH_ISSUER_URL: z.string().optional(),
|
||||
|
||||
SSH_AUTH_KEY: z.string().optional(),
|
||||
|
||||
ADMIN_SHARED_SECRET: z.string().optional(),
|
||||
|
||||
DATABASE_URL: z.string().optional()
|
||||
});
|
||||
|
||||
export type Info = z.infer<typeof Info>;
|
||||
|
||||
const _get = memo(() => Info.parse({ ...process.env, ..._overrides }));
|
||||
|
||||
export function get(): Info {
|
||||
return _get();
|
||||
}
|
||||
|
||||
export function init(bindings: Record<string, unknown>) {
|
||||
_overrides = {
|
||||
...bindings,
|
||||
...(bindings.HYPERDRIVE
|
||||
? {
|
||||
DATABASE_URL: (bindings.HYPERDRIVE as { connectionString: string }).connectionString
|
||||
}
|
||||
: {})
|
||||
};
|
||||
_get.reset();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user