Files
rxminder/services/couchdb.factory.ts
William Valentin 172bb2bd74 refactor: improve service layer logging and configuration
- Change email service logging from console.log to console.warn for better visibility
- Update mailgun and couchdb configuration with improved error handling
- Enhance database seeder with better logging and error management
- Improve service factory patterns for better testability
2025-09-07 15:22:04 -07:00

46 lines
1.3 KiB
TypeScript

// Production CouchDB Service Configuration
// This file determines whether to use mock localStorage or real CouchDB
import { CouchDBService as MockCouchDBService } from './couchdb';
import { getEnvVar, isTest } from '../utils/env';
// Environment detection
const isProduction = () => {
// Always use mock service in test environment
if (isTest()) {
return false;
}
// Check if we're in a Docker environment or if CouchDB URL is configured
const couchdbUrl = getEnvVar('VITE_COUCHDB_URL') || getEnvVar('COUCHDB_URL');
return !!couchdbUrl && couchdbUrl !== 'mock';
};
// Create the database service based on environment
const createDbService = () => {
if (isProduction()) {
try {
// Use dynamic require to avoid TypeScript resolution issues
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';