This commit is contained in:
37
app/app.config.js
Normal file
37
app/app.config.js
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Charge les variables d'environnement depuis `app/.env*` puis `../.env*`
|
||||
* (le repo a souvent `.env.local` à la racine `mdb/`, pas dans `mdb/app/`).
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function loadEnvFiles() {
|
||||
const dirs = [__dirname, path.join(__dirname, '..')];
|
||||
const names = ['.env.local', '.env'];
|
||||
for (const dir of dirs) {
|
||||
for (const name of names) {
|
||||
const full = path.join(dir, name);
|
||||
if (!fs.existsSync(full)) continue;
|
||||
const raw = fs.readFileSync(full, 'utf8');
|
||||
for (const line of raw.split('\n')) {
|
||||
const t = line.trim();
|
||||
if (!t || t.startsWith('#')) continue;
|
||||
const i = t.indexOf('=');
|
||||
if (i <= 0) continue;
|
||||
const key = t.slice(0, i).trim();
|
||||
let val = t.slice(i + 1).trim();
|
||||
if (
|
||||
(val.startsWith('"') && val.endsWith('"')) ||
|
||||
(val.startsWith("'") && val.endsWith("'"))
|
||||
) {
|
||||
val = val.slice(1, -1);
|
||||
}
|
||||
if (process.env[key] === undefined) process.env[key] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadEnvFiles();
|
||||
|
||||
module.exports = require('./app.json');
|
||||
Reference in New Issue
Block a user