Skip to content

Commit 978e231

Browse files
committed
fix(integration): pass .env vars to serve process
Production servers like react-router-serve don't auto-load .env files (unlike Vite dev or srvx CLI). Read the .env file and pass all vars as process env to the serve command so Clerk keys are available at runtime.
1 parent 7cc55ae commit 978e231

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

integration/models/application.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,26 @@ export const application = (
174174
return { port, serverUrl: runtimeServerUrl };
175175
}
176176

177+
// Read .env file and pass as process env vars since production servers
178+
// may not auto-load .env files (e.g., react-router-serve)
179+
const envFromFile: Record<string, string> = {};
180+
const envFilePath = path.resolve(appDirPath, '.env');
181+
if (fs.existsSync(envFilePath)) {
182+
const envContent = fs.readFileSync(envFilePath, 'utf-8');
183+
for (const line of envContent.split('\n')) {
184+
const trimmed = line.trim();
185+
if (trimmed && !trimmed.startsWith('#')) {
186+
const eqIdx = trimmed.indexOf('=');
187+
if (eqIdx > 0) {
188+
envFromFile[trimmed.slice(0, eqIdx)] = trimmed.slice(eqIdx + 1);
189+
}
190+
}
191+
}
192+
}
193+
177194
const proc = run(scripts.serve, {
178195
cwd: appDirPath,
179-
env: { PORT: port.toString() },
196+
env: { ...envFromFile, PORT: port.toString() },
180197
detached: opts.detached,
181198
stdout: opts.detached ? fs.openSync(stdoutFilePath, 'a') : undefined,
182199
stderr: opts.detached ? fs.openSync(stderrFilePath, 'a') : undefined,

0 commit comments

Comments
 (0)