From e36352b7f3c4a3d7d617f84b5001296a6ee000d4 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Tue, 11 Mar 2025 21:58:25 -0400 Subject: [PATCH] fix: define globals for context --- app/utils/config/parser.ts | 4 ++-- app/utils/oidc.ts | 6 +----- server/context/globals.ts | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 server/context/globals.ts diff --git a/app/utils/config/parser.ts b/app/utils/config/parser.ts index 7363987..4e0046b 100644 --- a/app/utils/config/parser.ts +++ b/app/utils/config/parser.ts @@ -105,8 +105,8 @@ const headscaleConfig = type({ magic_dns: goBool.default(true), base_domain: 'string = "headscale.net"', nameservers: type({ - 'global?': 'string[]', - 'split': type('Record').default(() => ({})), + global: type('string[]').default(() => []), + split: type('Record').default(() => ({})), }).default(() => ({ global: [], split: {} })), search_domains: type('string[]').default(() => []), extra_records: type({ diff --git a/app/utils/oidc.ts b/app/utils/oidc.ts index 2b662c8..8515b5b 100644 --- a/app/utils/oidc.ts +++ b/app/utils/oidc.ts @@ -6,10 +6,6 @@ import log from '~server/utils/log'; type OidcConfig = NonNullable; declare global { const __PREFIX__: string; - const __oidc_context: { - valid: boolean; - secret: string; - }; } // We try our best to infer the callback URI of our Headplane instance @@ -260,7 +256,7 @@ export function formatError(error: unknown) { } export function oidcEnabled() { - return __oidc_valid; + return __oidc_context.valid; } export async function testOidc(oidc: OidcConfig) { diff --git a/server/context/globals.ts b/server/context/globals.ts new file mode 100644 index 0000000..9ca8fc0 --- /dev/null +++ b/server/context/globals.ts @@ -0,0 +1,21 @@ +import { HeadplaneConfig } from './parser'; + +declare global { + const __cookie_context: { + cookie_secret: string; + cookie_secure: boolean; + }; + + const __hs_context: { + url: string; + config_path?: string; + config_strict?: boolean; + }; + + const __oidc_context: { + valid: boolean; + secret: string; + }; + + let __integration_context: HeadplaneConfig['integration']; +}