Initial commit: Complete NodeJS-native setup
- Migrated from Python pre-commit to NodeJS-native solution - Reorganized documentation structure - Set up Husky + lint-staged for efficient pre-commit hooks - Fixed Dockerfile healthcheck issue - Added comprehensive documentation index
This commit is contained in:
44
services/couchdb.factory.ts
Normal file
44
services/couchdb.factory.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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';
|
||||
Reference in New Issue
Block a user