forked from gilbertofke/Klymate-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
70 lines (59 loc) · 2.19 KB
/
Copy pathdatabase.js
File metadata and controls
70 lines (59 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// src/config/database.js
// TiDB connection configuration for your React app
class DatabaseConfig {
constructor() {
this.config = {
host: import.meta.env.VITE_TIDB_HOST,
port: parseInt(import.meta.env.VITE_TIDB_PORT) || 4000,
username: import.meta.env.VITE_TIDB_USERNAME,
password: import.meta.env.VITE_TIDB_PASSWORD,
database: import.meta.env.VITE_TIDB_DATABASE,
ssl: {
rejectUnauthorized: true
},
connectionLimit: 10,
acquireTimeout: 60000,
timeout: 60000,
reconnect: true
};
// Validate required environment variables
this.validateConfig();
}
validateConfig() {
const required = ['host', 'username', 'password', 'database'];
const missing = required.filter(key => !this.config[key]);
if (missing.length > 0) {
console.error('Missing required TiDB environment variables:', missing);
console.warn('Please check your .env file and ensure all TiDB variables are set');
}
}
getConnectionString() {
const { host, port, username, password, database } = this.config;
return `mysql://${username}:${password}@${host}:${port}/${database}?ssl={"rejectUnauthorized":true}`;
}
getApiConfig() {
return {
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000/api',
endpoints: {
auth: import.meta.env.VITE_AUTH_ENDPOINT || '/auth',
habits: import.meta.env.VITE_HABITS_ENDPOINT || '/habits',
ai: import.meta.env.VITE_AI_ENDPOINT || '/ai',
gamification: import.meta.env.VITE_GAMIFICATION_ENDPOINT || '/gamification',
carbon: import.meta.env.VITE_CARBON_ENDPOINT || '/carbon'
}
};
}
isDevelopment() {
return import.meta.env.VITE_NODE_ENV === 'development';
}
isDebugEnabled() {
return import.meta.env.VITE_DEBUG_MODE === 'true';
}
}
// Create singleton instance
const dbConfig = new DatabaseConfig();
export default dbConfig;
// Export individual configs for easier imports
export const tidbConfig = dbConfig.config;
export const apiConfig = dbConfig.getApiConfig();
export const connectionString = dbConfig.getConnectionString();