import dotenv from 'dotenv'; import { rootPath } from './constPath.js'; import { unwrap } from '@sammo/util'; let init = false; const dirPath = rootPath console.log(rootPath); function initDotEnv() { if (process.env['NODE_ENV'] == 'production') { dotenv.config({ path: `${dirPath}/.env.production.local` }); dotenv.config({ path: `${dirPath}/.env.local` }); dotenv.config({ path: `${dirPath}/.env.production` }); } else { dotenv.config({ path: `${dirPath}/.env.development.local` }); dotenv.config({ path: `${dirPath}/.env.local` }); dotenv.config({ path: `${dirPath}/.env.development` }); } dotenv.config(); init = true; } if (!init) { initDotEnv(); } let _ownConfig: ReturnType|undefined = undefined; function generateConfig() { return { port: parseInt(process.env['SERVER_PORT'] ?? "3001"), sessionSecret: unwrap(process.env['SESSION_SECRET']), apiRootPath: process.env['API_ROOT_PATH'] ?? '/api', } as const; } export function ownConfig() { if(_ownConfig !== undefined){ return _ownConfig; } if(!init){ initDotEnv(); } _ownConfig = generateConfig(); return _ownConfig; }