// Production CouchDB Service Configuration // This file determines whether to use mock localStorage or real CouchDB import { CouchDBService as MockCouchDBService } from './couchdb'; // Environment detection const isProduction = () => { // Check if we're in a Docker environment or if CouchDB URL is configured const env = (import.meta as any).env || {}; const couchdbUrl = env.VITE_COUCHDB_URL || (typeof process !== 'undefined' ? process.env.VITE_COUCHDB_URL : null) || (typeof process !== 'undefined' ? process.env.COUCHDB_URL : null); return !!couchdbUrl && couchdbUrl !== 'mock'; }; // Create the database service based on environment const createDbService = () => { if (isProduction()) { try { // Use dynamic require to avoid TypeScript resolution issues // eslint-disable-next-line @typescript-eslint/no-var-requires const { CouchDBService: RealCouchDBService, } = require('./couchdb.production'); return new RealCouchDBService(); } catch (error) { console.warn( 'Production CouchDB service not available, falling back to mock:', error ); return new MockCouchDBService(); } } else { return new MockCouchDBService(); } }; // Export the database service instance export const dbService = createDbService(); // Re-export the error class export { CouchDBError } from './couchdb';