diff --git a/nais/dev-gcp-ekstern.yaml b/nais/dev-gcp-ekstern.yaml index ff810796..9d2a34a2 100644 --- a/nais/dev-gcp-ekstern.yaml +++ b/nais/dev-gcp-ekstern.yaml @@ -36,8 +36,6 @@ spec: value: https://arbeidsgiver.ekstern.dev.nav.no/min-side-arbeidsgiver - name: FOREBYGGE_FRAVAR_URL value: https://arbeidsgiver.ekstern.dev.nav.no/forebygge-fravar - - name: GRAFANA_AGENT_COLLECTOR_URL - value: null accessPolicy: outbound: external: diff --git a/server/src/environment.ts b/server/src/environment.ts index 6296565a..21b0e25a 100644 --- a/server/src/environment.ts +++ b/server/src/environment.ts @@ -1,4 +1,4 @@ -import { z } from 'zod'; +import { z, ZodEffects, ZodOptional, ZodString } from 'zod'; import { logger } from './backend-logger.js'; export const MILJØ = { @@ -12,6 +12,7 @@ export type MILJØ = (typeof MILJØ)[keyof typeof MILJØ]; const isMiljø = (value: string): value is MILJØ => { return (Object.values(MILJØ) as string[]).includes(value); }; + function getCurrentEnvironment() { const { MILJO = 'local' } = process.env; return MILJO; @@ -20,15 +21,34 @@ function getCurrentEnvironment() { function errorMap(issue: z.ZodIssueOptionalMessage, ctx: z.ErrorMapCtx): { message: string } { return { message: `Kunne ikke parse miljøvariabler. [${ctx.defaultError}]` }; } + export function getFrontendEnvs() { try { - return z + const miljø = z .object({ MILJO: z.string().refine(isMiljø), - MIN_SIDE_ARBEIDSGIVER_URL: z.string().url(), - GRAFANA_AGENT_COLLECTOR_URL: z.string().url(), }) .parse(process.env, { errorMap: errorMap }); + + let shape: { + GRAFANA_AGENT_COLLECTOR_URL: ZodString | ZodOptional; + MIN_SIDE_ARBEIDSGIVER_URL: ZodString; + MILJO: ZodEffects; + } = { + MILJO: z.string().refine(isMiljø), + MIN_SIDE_ARBEIDSGIVER_URL: z.string().url(), + GRAFANA_AGENT_COLLECTOR_URL: z.string().url(), + }; + + if (miljø.MILJO === MILJØ.DEV_EKSTERN) { + shape = { + MILJO: z.string().refine(isMiljø), + MIN_SIDE_ARBEIDSGIVER_URL: z.string().url(), + GRAFANA_AGENT_COLLECTOR_URL: z.string().url().optional(), + }; + } + + return z.object(shape).parse(process.env, { errorMap: errorMap }); } catch (err) { if (process.env.NODE_ENV === 'development') { return {