MCPcopy Create free account
hub / github.com/ShipSecAI/studio / loadFrontendEnv

Function loadFrontendEnv

pm2.config.cjs:166–198  ·  view source on GitHub ↗
(envFilePath)

Source from the content-addressed store, hash-verified

164
165// Load .env file and extract VITE_* variables for frontend
166function loadFrontendEnv(envFilePath) {
167 const env = { NODE_ENV: 'development' };
168
169 try {
170 if (fs.existsSync(envFilePath)) {
171 const envContent = fs.readFileSync(envFilePath, 'utf-8');
172 envContent.split('\n').forEach((line) => {
173 const trimmed = line.trim();
174 // Skip comments and empty lines
175 if (!trimmed || trimmed.startsWith('#')) {
176 return;
177 }
178 const match = trimmed.match(/^([^=]+)=(.*)$/);
179 if (match) {
180 const key = match[1].trim();
181 let value = match[2].trim();
182 // Remove surrounding quotes if present
183 if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
184 value = value.slice(1, -1);
185 }
186 // Only include VITE_* variables for frontend
187 if (key.startsWith('VITE_')) {
188 env[key] = value;
189 }
190 }
191 });
192 }
193 } catch (err) {
194 console.warn('Failed to load frontend .env file:', err.message);
195 }
196
197 return env;
198}
199
200// Load worker .env file for OpenSearch and other worker-specific variables
201function loadWorkerEnv() {

Callers 1

pm2.config.cjsFile · 0.85

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected