Files
core_ng/@sammo/gateway_server/src/dotenv.ts
T
Hide_D e59f9a9659 monorepo 버전 준비
## @strpc
기존 RPC를 package화

### @strpc/express
express의 middleware + router 결함

## @sammo
게임 전체
- server, client
- gateway_server, gateway_client
2023-09-23 16:29:18 +00:00

48 lines
1.1 KiB
TypeScript

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<typeof generateConfig>|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;
}