## @strpc 기존 RPC를 package화 ### @strpc/express express의 middleware + router 결함 ## @sammo 게임 전체 - server, client - gateway_server, gateway_client
48 lines
1.1 KiB
TypeScript
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;
|
|
}
|