refactor(web): treat NEXT_PUBLIC env-config as packaged-client fallback

This commit is contained in:
Anish Sarkar 2026-06-16 01:38:33 +05:30
parent 5613908d0d
commit 2da4a29a4d
2 changed files with 22 additions and 38 deletions

View file

@ -1,56 +1,37 @@
/** /**
* Environment configuration for the frontend. * Environment configuration for the frontend.
* *
* This file centralizes access to NEXT_PUBLIC_* environment variables. * Docker deployments use same-origin relative browser URLs behind Caddy.
* For Docker deployments, these placeholders are replaced at container startup * NEXT_PUBLIC_* values remain only as build-time fallbacks for packaged clients
* via sed in the entrypoint script. * like Electron, where there is no bundled Caddy origin.
*
* IMPORTANT: Do not use template literals or complex expressions with these values
* as it may prevent the sed replacement from working correctly.
*/ */
import packageJson from "../package.json"; import packageJson from "../package.json";
// Auth type: "LOCAL" for email/password, "GOOGLE" for OAuth // Build-time fallback for packaged clients. Docker runtime reads plain AUTH_TYPE
// Placeholder: __NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE__ // through the runtime config provider instead.
export const AUTH_TYPE = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE || "GOOGLE"; export const AUTH_TYPE = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE || "GOOGLE";
// Backend API URL. An empty string is valid in proxy mode and means // Backend API URL. An empty string is valid in proxy mode and means
// same-origin relative requests (e.g. /api/v1/... and /auth/...). // same-origin relative requests (e.g. /api/v1/... and /auth/...).
// Placeholder: __NEXT_PUBLIC_FASTAPI_BACKEND_URL__ export const BACKEND_URL = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL ?? "";
export const BACKEND_URL = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL ?? "http://localhost:8000";
// Server-side backend URL. Relative browser URLs do not work from RSC/API route // Server-side backend URL. Relative browser URLs do not work from RSC/API route
// code, so server callers should use Docker DNS or an explicit public backend. // code, so server callers should use Docker DNS or an explicit public backend.
export const SERVER_BACKEND_URL = export const SERVER_BACKEND_URL =
process.env.SURFSENSE_BACKEND_INTERNAL_URL ||
// TODO: Remove FASTAPI_BACKEND_INTERNAL_URL after the post-Caddy env migration window.
process.env.FASTAPI_BACKEND_INTERNAL_URL || process.env.FASTAPI_BACKEND_INTERNAL_URL ||
process.env.BACKEND_URL || "http://backend:8000";
BACKEND_URL ||
"http://localhost:8000";
// ETL Service: "DOCLING", "UNSTRUCTURED", or "LLAMACLOUD" // Build-time fallback for packaged clients. Docker runtime reads plain ETL_SERVICE
// Placeholder: __NEXT_PUBLIC_ETL_SERVICE__ // through the runtime config provider instead.
export const ETL_SERVICE = process.env.NEXT_PUBLIC_ETL_SERVICE || "DOCLING"; export const ETL_SERVICE = process.env.NEXT_PUBLIC_ETL_SERVICE || "DOCLING";
// Deployment Mode: "self-hosted" or "cloud" // Build-time fallback for packaged clients. Docker runtime reads plain
// Matches backend's SURFSENSE_DEPLOYMENT_MODE - defaults to "self-hosted" // DEPLOYMENT_MODE through the runtime config provider instead.
// self-hosted: Full access to local file system connectors (Obsidian, etc.)
// cloud: Only cloud-based connectors available
// Placeholder: __NEXT_PUBLIC_DEPLOYMENT_MODE__
export const DEPLOYMENT_MODE = process.env.NEXT_PUBLIC_DEPLOYMENT_MODE || "self-hosted"; export const DEPLOYMENT_MODE = process.env.NEXT_PUBLIC_DEPLOYMENT_MODE || "self-hosted";
// App version - defaults to package.json version // App version - defaults to package.json version
// Can be overridden at build time with NEXT_PUBLIC_APP_VERSION for full git tag version // Can be overridden at build time with NEXT_PUBLIC_APP_VERSION for full git tag version
export const APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION || packageJson.version; export const APP_VERSION = process.env.NEXT_PUBLIC_APP_VERSION || packageJson.version;
// Helper to check if local auth is enabled
export const isLocalAuth = () => AUTH_TYPE === "LOCAL";
// Helper to check if Google auth is enabled
export const isGoogleAuth = () => AUTH_TYPE === "GOOGLE";
// Helper to check if running in self-hosted mode
export const isSelfHosted = () => DEPLOYMENT_MODE === "self-hosted";
// Helper to check if running in cloud mode
export const isCloud = () => DEPLOYMENT_MODE === "cloud";

View file

@ -75,18 +75,21 @@ export const FILE_TYPE_CONFIG: Record<string, Record<string, string[]>> = {
}, },
}; };
export function getAcceptedFileTypes(): Record<string, string[]> { export function getAcceptedFileTypes(etlService?: string): Record<string, string[]> {
const etlService = process.env.NEXT_PUBLIC_ETL_SERVICE;
return FILE_TYPE_CONFIG[etlService || "default"] || FILE_TYPE_CONFIG.default; return FILE_TYPE_CONFIG[etlService || "default"] || FILE_TYPE_CONFIG.default;
} }
export function getSupportedExtensions(acceptedFileTypes?: Record<string, string[]>): string[] { export function getSupportedExtensions(
const types = acceptedFileTypes ?? getAcceptedFileTypes(); acceptedFileTypes?: Record<string, string[]>,
etlService?: string
): string[] {
const types = acceptedFileTypes ?? getAcceptedFileTypes(etlService);
return Array.from(new Set(Object.values(types).flat())).sort(); return Array.from(new Set(Object.values(types).flat())).sort();
} }
export function getSupportedExtensionsSet( export function getSupportedExtensionsSet(
acceptedFileTypes?: Record<string, string[]> acceptedFileTypes?: Record<string, string[]>,
etlService?: string
): Set<string> { ): Set<string> {
return new Set(getSupportedExtensions(acceptedFileTypes).map((ext) => ext.toLowerCase())); return new Set(getSupportedExtensions(acceptedFileTypes, etlService).map((ext) => ext.toLowerCase()));
} }