mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 11:54:10 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			990 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			990 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
'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;
 | 
						|
 | 
						|
const getClientEnvironment = (options) => {
 | 
						|
  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,
 | 
						|
        NODE_ENV: options.env || 'development',
 | 
						|
        STRAPI_ADMIN_BACKEND_URL: options.backend,
 | 
						|
        STRAPI_TELEMETRY_DISABLED: options.telemetryDisabled,
 | 
						|
      }
 | 
						|
    );
 | 
						|
 | 
						|
  const stringified = {
 | 
						|
    'process.env': Object.keys(raw).reduce((env, key) => {
 | 
						|
      env[key] = JSON.stringify(raw[key]);
 | 
						|
      return env;
 | 
						|
    }, {}),
 | 
						|
  };
 | 
						|
 | 
						|
  return stringified;
 | 
						|
};
 | 
						|
 | 
						|
module.exports = getClientEnvironment;
 |