monorepo 버전 준비
## @strpc 기존 RPC를 package화 ### @strpc/express express의 middleware + router 결함 ## @sammo 게임 전체 - server, client - gateway_server, gateway_client
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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']),
|
||||
gatewayHost: unwrap(process.env.GATEWAY_HOST),
|
||||
gatewayPort: Number(unwrap(process.env.GATEWAY_PORT)),
|
||||
apiRootPath: process.env['API_ROOT_PATH'] ?? '/api',
|
||||
} as const;
|
||||
}
|
||||
|
||||
export function serverConfig() {
|
||||
if(_ownConfig !== undefined){
|
||||
return _ownConfig;
|
||||
}
|
||||
if(!init){
|
||||
initDotEnv();
|
||||
}
|
||||
_ownConfig = generateConfig();
|
||||
return _ownConfig;
|
||||
}
|
||||
Reference in New Issue
Block a user