refactor: standardize env and directus logic using enhanced @mintel/next-utils
Some checks failed
Some checks failed
This commit is contained in:
@@ -3,19 +3,8 @@ import { createMintelDirectusClient, ensureDirectusAuthenticated } from '@mintel
|
|||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
import { getServerAppServices } from './services/create-services.server';
|
import { getServerAppServices } from './services/create-services.server';
|
||||||
|
|
||||||
const { url, proxyPath, internalUrl } = config.directus;
|
// Initialize client using Mintel standards (environment-aware)
|
||||||
|
const client = createMintelDirectusClient();
|
||||||
// Use internal URL if on server to bypass Gatekeeper/Auth
|
|
||||||
// Use proxy path in browser to stay on the same origin (CORS safe)
|
|
||||||
const effectiveUrl =
|
|
||||||
typeof window === 'undefined'
|
|
||||||
? internalUrl || url
|
|
||||||
: typeof window !== 'undefined'
|
|
||||||
? `${window.location.origin}${proxyPath}`
|
|
||||||
: proxyPath;
|
|
||||||
|
|
||||||
// Initialize client using Mintel standards
|
|
||||||
const client = createMintelDirectusClient(effectiveUrl);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to determine if we should show detailed errors
|
* Helper to determine if we should show detailed errors
|
||||||
@@ -65,8 +54,8 @@ function mapDirectusProduct(item: any, locale: string): any {
|
|||||||
voltageTables: translation.voltage_tables || [],
|
voltageTables: translation.voltage_tables || [],
|
||||||
},
|
},
|
||||||
locale: locale,
|
locale: locale,
|
||||||
// Use proxy URL for assets to avoid CORS and handle internal/external issues
|
// Use standardized proxy path for assets to avoid CORS
|
||||||
data_sheet_url: item.data_sheet ? `${proxyPath}/assets/${item.data_sheet}` : null,
|
data_sheet_url: item.data_sheet ? `/api/directus/assets/${item.data_sheet}` : null,
|
||||||
categories: (item.categories_link || [])
|
categories: (item.categories_link || [])
|
||||||
.map((c: any) => c.categories_id?.translations?.[0]?.name)
|
.map((c: any) => c.categories_id?.translations?.[0]?.name)
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
|
|||||||
21
lib/env.ts
21
lib/env.ts
@@ -3,20 +3,20 @@ import { validateMintelEnv, mintelEnvSchema } from '@mintel/next-utils';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Environment variable schema.
|
* Environment variable schema.
|
||||||
* Extends the default Mintel environment schema.
|
* Extends the default Mintel environment schema which already includes:
|
||||||
|
* - Directus (URL, TOKEN, INTERNAL_URL, etc.)
|
||||||
|
* - Mail (HOST, PORT, etc.)
|
||||||
|
* - Gotify
|
||||||
|
* - Logging
|
||||||
|
* - Analytics
|
||||||
*/
|
*/
|
||||||
export const envSchema = z.object({
|
export const envSchema = z.object({
|
||||||
...mintelEnvSchema,
|
...mintelEnvSchema,
|
||||||
// Project specific variables
|
|
||||||
NEXT_PUBLIC_TARGET: z.enum(['development', 'testing', 'staging', 'production']).optional(),
|
|
||||||
TARGET: z.enum(['development', 'testing', 'staging', 'production']).optional(),
|
|
||||||
|
|
||||||
// Directus (Extended from base)
|
// Project specific overrides or additions
|
||||||
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
|
AUTH_COOKIE_NAME: z.string().default('klz_gatekeeper_session'),
|
||||||
INFRA_DIRECTUS_URL: z.string().url().optional(),
|
|
||||||
INFRA_DIRECTUS_TOKEN: z.string().optional(),
|
|
||||||
|
|
||||||
// Gatekeeper
|
// Gatekeeper specifics not in base
|
||||||
GATEKEEPER_URL: z.string().url().default('http://gatekeeper:3000'),
|
GATEKEEPER_URL: z.string().url().default('http://gatekeeper:3000'),
|
||||||
GATEKEEPER_BYPASS_ENABLED: z.preprocess(
|
GATEKEEPER_BYPASS_ENABLED: z.preprocess(
|
||||||
(val) => val === 'true' || val === true,
|
(val) => val === 'true' || val === true,
|
||||||
@@ -26,6 +26,9 @@ export const envSchema = z.object({
|
|||||||
(val) => val === 'true' || val === true,
|
(val) => val === 'true' || val === true,
|
||||||
z.boolean().default(false),
|
z.boolean().default(false),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
INFRA_DIRECTUS_URL: z.string().url().optional(),
|
||||||
|
INFRA_DIRECTUS_TOKEN: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user