Skip to content

Commit caab78a

Browse files
Merge pull request #32 from contentstack/chore/better-env-handling
Enhance environment variable loading: read from .env for development and process.env for production
2 parents 0f80787 + 5ea0a0e commit caab78a

File tree

3 files changed

+1072
-629
lines changed

3 files changed

+1072
-629
lines changed

generate-env.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ const envPath = path.join(__dirname, ".env");
1313
let envVars = {};
1414

1515
if (fs.existsSync(envPath)) {
16+
// Development: read from .env file
1617
const envContent = fs.readFileSync(envPath, "utf8");
1718
envContent.split("\n").forEach((line) => {
1819
const [key, value] = line.split("=");
1920
if (key && value) {
2021
envVars[key.trim()] = value.trim();
2122
}
2223
});
24+
} else {
25+
// Production: read from process.env
26+
Object.keys(process.env).forEach((key) => {
27+
if (key.startsWith('NG_APP_CONTENTSTACK_')) {
28+
envVars[key] = process.env[key];
29+
}
30+
});
2331
}
2432

2533
const region = getRegionForString(envVars.NG_APP_CONTENTSTACK_REGION);

0 commit comments

Comments
 (0)