Skip to content

Commit bb1df64

Browse files
committed
feat: updated documentation to include remote config
1 parent 9b1fbcd commit bb1df64

2 files changed

Lines changed: 47 additions & 38 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ dist
117117
# Stores VSCode versions used for testing VSCode extensions
118118
.vscode-test
119119

120+
# Jetbrains
121+
.idea
122+
120123
# yarn v2
121124

122125
.yarn/cache

src/config/index.js

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const fs = require('fs');
22
const ConfigLoader = require('./ConfigLoader');
3-
const proxy = require('../proxy');
43
const { validate } = require('./file'); // Import the validate function
54

65
const defaultSettings = require('../../proxy.config.json');
@@ -17,43 +16,6 @@ let _config = { ...defaultSettings, ...(_userSettings || {}) };
1716
// Create config loader instance
1817
const configLoader = new ConfigLoader(_config);
1918

20-
// Handle configuration updates
21-
configLoader.on('configurationChanged', async (newConfig) => {
22-
console.log('Configuration updated from external source');
23-
try {
24-
// 1. Stop existing services
25-
await proxy.stop();
26-
27-
// 2. Update config
28-
_config = newConfig;
29-
30-
// 3. Validate new configuration
31-
validate(); // Use the imported validate function
32-
33-
// 4. Restart services with new config
34-
await proxy.start();
35-
36-
console.log('Services restarted with new configuration');
37-
} catch (error) {
38-
console.error('Failed to apply new configuration:', error);
39-
// Attempt to restart with previous config
40-
try {
41-
await proxy.start();
42-
} catch (startError) {
43-
console.error('Failed to restart services:', startError);
44-
}
45-
}
46-
});
47-
48-
configLoader.on('configurationError', (error) => {
49-
console.error('Error loading external configuration:', error);
50-
});
51-
52-
// Start the config loader if external sources are enabled
53-
configLoader.start().catch((error) => {
54-
console.error('Failed to start configuration loader:', error);
55-
});
56-
5719
// Helper function to get current config value
5820
const getConfig = (key) => {
5921
return _config[key];
@@ -109,6 +71,50 @@ const logConfiguration = () => {
10971
console.log(`authentication = ${JSON.stringify(getAuthentication())}`);
11072
};
11173

74+
// Function to handle configuration updates
75+
const handleConfigUpdate = async (newConfig) => {
76+
console.log('Configuration updated from external source');
77+
try {
78+
// 1. Get proxy module dynamically to avoid circular dependency
79+
const proxy = require('../proxy');
80+
81+
// 2. Stop existing services
82+
await proxy.stop();
83+
84+
// 3. Update config
85+
_config = newConfig;
86+
87+
// 4. Validate new configuration
88+
validate();
89+
90+
// 5. Restart services with new config
91+
await proxy.start();
92+
93+
console.log('Services restarted with new configuration');
94+
} catch (error) {
95+
console.error('Failed to apply new configuration:', error);
96+
// Attempt to restart with previous config
97+
try {
98+
const proxy = require('../proxy');
99+
await proxy.start();
100+
} catch (startError) {
101+
console.error('Failed to restart services:', startError);
102+
}
103+
}
104+
};
105+
106+
// Handle configuration updates
107+
configLoader.on('configurationChanged', handleConfigUpdate);
108+
109+
configLoader.on('configurationError', (error) => {
110+
console.error('Error loading external configuration:', error);
111+
});
112+
113+
// Start the config loader if external sources are enabled
114+
configLoader.start().catch((error) => {
115+
console.error('Failed to start configuration loader:', error);
116+
});
117+
112118
// Force reload of configuration
113119
const reloadConfiguration = async () => {
114120
await configLoader.reloadConfiguration();

0 commit comments

Comments
 (0)