2021-05-05 10:48:27 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
const dotenvFilePath = path.resolve(process.cwd(), '.env');
|
|
|
|
|
|
|
|
if (fs.existsSync(dotenvFilePath)) {
|
|
|
|
dotenv.config({ path: dotenvFilePath });
|
|
|
|
}
|
|
|
|
|
|
|
|
const STRAPI_ADMIN = /^STRAPI_ADMIN_/i;
|
|
|
|
|
2021-07-01 15:50:11 +02:00
|
|
|
const getClientEnvironment = options => {
|
2021-05-05 10:48:27 +02:00
|
|
|
const raw = Object.keys(process.env)
|
|
|
|
.filter(key => STRAPI_ADMIN.test(key))
|
|
|
|
.reduce(
|
|
|
|
(acc, current) => {
|
|
|
|
acc[current] = process.env[current];
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ADMIN_PATH: options.adminPath,
|
2021-05-12 10:28:20 +02:00
|
|
|
NODE_ENV: options.env || 'development',
|
2021-05-05 17:52:41 +02:00
|
|
|
STRAPI_ADMIN_BACKEND_URL: options.backend,
|
2021-05-05 10:48:27 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-05-05 17:52:41 +02:00
|
|
|
const stringified = {
|
|
|
|
'process.env': Object.keys(raw).reduce((env, key) => {
|
|
|
|
env[key] = JSON.stringify(raw[key]);
|
|
|
|
return env;
|
|
|
|
}, {}),
|
|
|
|
};
|
2021-05-05 10:48:27 +02:00
|
|
|
|
2021-05-05 15:41:23 +02:00
|
|
|
return stringified;
|
2021-05-05 10:48:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getClientEnvironment;
|