diff --git a/dev.local.ecosystem.config.js b/dev.local.ecosystem.config.js new file mode 100644 index 00000000..f508bdcc --- /dev/null +++ b/dev.local.ecosystem.config.js @@ -0,0 +1,13 @@ +module.exports = { + apps: [ + { + name: 'qcast-front-local-development', + script: 'node_modules/next/dist/bin/next', + instances: 1, + exec_mode: 'fork', + env: { + PORT: 5000, + }, + }, + ], +} diff --git a/ecosystem.config.js b/ecosystem.config.js index 6bf049da..c4ffc467 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -6,7 +6,7 @@ module.exports = { instances: 2, exec_mode: 'cluster', env: { - PORT: 5000, + NODE_ENV: 'production', }, }, ], diff --git a/package.json b/package.json index bbddf9ad..d784f800 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,14 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", - "build": "next build", - "start:cluster1": "next start -p 5000", - "start:cluster2": "next start -p 5001", - "start:dev": "next start -p 5010", + "dev": "env-cmd -f .env.localhost next dev", + "local:dev": "env-cmd -f .env.local.dev next dev", + "build": "env-cmd -f .env.productionnext build", + "build:dev": "env-cmd -f .env.development next build", + "build:local.dev": "env-cmd -f .env.local.dev next build", + "start:cluster1": "env-cmd -f .env.production next start -p 5000", + "start:cluster2": "env-cmd -f .env.production next start -p 5001", + "start:dev": "env-cmd -f .env.development next start -p 5010", "lint": "next lint", "serve": "node server.js" }, @@ -18,6 +21,7 @@ "big.js": "^6.2.2", "chart.js": "^4.4.6", "dayjs": "^1.11.13", + "env-cmd": "^10.1.0", "fabric": "^5.3.0", "framer-motion": "^11.2.13", "fs": "^0.0.1-security", diff --git a/src/config/config.common.js b/src/config/config.common.js new file mode 100644 index 00000000..dc2208ae --- /dev/null +++ b/src/config/config.common.js @@ -0,0 +1,11 @@ +// local, development, production 과 관계없이 동일한 값으로 반환되는 부분은 해당 함수의 return 되는 부분만 수정하면 됩니다. (달라져야 하는 값이 아닌, 같은 값에 대해서는 local, development, production 파일을 모두 수정할 필요가 없어지게 됩니다.) +export default function getConfigs(params) { + // local, development, production 마다 달라지는 값 + const { baseUrl, mode } = params + + // 공통으로 반환되는 구조 + return { + baseUrl, + mode, + } +} diff --git a/src/config/config.development.js b/src/config/config.development.js new file mode 100644 index 00000000..2c9870a4 --- /dev/null +++ b/src/config/config.development.js @@ -0,0 +1,13 @@ +import getConfigs from './config.common' + +// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 development 환경에 맞는 값을 지정합니다.) +const baseUrl = 'https://dev.hanssys.jp' +const mode = 'development' + +// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다. +const configDevelopment = getConfigs({ + baseUrl, + mode, +}) + +export default configDevelopment diff --git a/src/config/config.export.js b/src/config/config.export.js new file mode 100644 index 00000000..650e1f58 --- /dev/null +++ b/src/config/config.export.js @@ -0,0 +1,22 @@ +import configDevelopment from './config.development' +import configLocal from './config.local' +import configLocalDev from './config.local.dev' +import configProduction from './config.production' + +// 클라이언트에서는 이 함수를 사용하여 config 값을 참조합니다. +const Config = () => { + switch (process.env.NEXT_PUBLIC_RUN_MODE) { + case 'local': + return configLocal + case 'local.dev': + return configLocalDev + case 'development': + return configDevelopment + case 'production': + return configProduction + default: + return configLocal + } +} + +export default Config diff --git a/src/config/config.local.dev.js b/src/config/config.local.dev.js new file mode 100644 index 00000000..5ba35451 --- /dev/null +++ b/src/config/config.local.dev.js @@ -0,0 +1,13 @@ +import getConfigs from './config.common' + +// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 local 환경에 맞는 값을 지정합니다.) +const baseUrl = 'http://1.248.227.176:5000' +const mode = 'local.dev' + +// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다. +const configLocalDev = getConfigs({ + baseUrl, + mode, +}) + +export default configLocalDev diff --git a/src/config/config.local.js b/src/config/config.local.js new file mode 100644 index 00000000..b0bee8ad --- /dev/null +++ b/src/config/config.local.js @@ -0,0 +1,13 @@ +import getConfigs from './config.common' + +// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 local 환경에 맞는 값을 지정합니다.) +const baseUrl = 'http://localhost:3000' +const mode = 'local' + +// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다. +const configLocal = getConfigs({ + baseUrl, + mode, +}) + +export default configLocal diff --git a/src/config/config.production.js b/src/config/config.production.js new file mode 100644 index 00000000..fc012875 --- /dev/null +++ b/src/config/config.production.js @@ -0,0 +1,13 @@ +import getConfigs from './config.common' + +// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 production 환경에 맞는 값을 지정합니다.) +const baseUrl = 'https://www.hanasys.jp' +const mode = 'production' + +// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다. +const configProduction = getConfigs({ + baseUrl, + mode, +}) + +export default configProduction diff --git a/src/hooks/common/useRefFiles.js b/src/hooks/common/useRefFiles.js index 366f5589..90c96f30 100644 --- a/src/hooks/common/useRefFiles.js +++ b/src/hooks/common/useRefFiles.js @@ -97,7 +97,7 @@ export function useRefFiles() { setPopSpinnerStore(true) console.log('🚀 ~ handleFileDelete ~ handleFileDelete:', refImage) console.log('🚀 ~ handleFileDelete ~ currentCanvasPlan.bgImageName:', currentCanvasPlan.bgImageName) - await del({ url: `${process.env.NEXT_PUBLIC_API_HOST_URL}/api/image/upload?fileName=${currentCanvasPlan.bgImageName}` }) + await del({ url: `${Config().baseUrl}/api/image/upload?fileName=${currentCanvasPlan.bgImageName}` }) setCurrentBgImage(null) await deleteBackGroundImage({ objectId: currentCanvasPlan.id, @@ -118,7 +118,7 @@ export function useRefFiles() { confirmFn: async () => { console.log('🚀 ~ handleAddressDelete ~ handleAddressDelete:', refImage) console.log('🚀 ~ handleAddressDelete ~ currentCanvasPlan.bgImageName:', currentCanvasPlan.bgImageName) - await del({ url: `${process.env.NEXT_PUBLIC_API_HOST_URL}/api/image/map?fileName=${currentCanvasPlan.bgImageName}` }) + await del({ url: `${Config().baseUrl}/api/image/map?fileName=${currentCanvasPlan.bgImageName}` }) setMapPositionAddress('') setCurrentBgImage(null) await deleteBackGroundImage({ @@ -149,7 +149,7 @@ export function useRefFiles() { })) const res = await get({ - url: `${process.env.NEXT_PUBLIC_API_HOST_URL}/api/image/map?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`, + url: `${Config().baseUrl}/api/image/map?q=${queryRef.current.value}&fileNm=${currentCanvasPlan.id}&zoom=20`, }) console.log('🚀 ~ handleMapImageDown ~ res:', res) setCurrentBgImage(`${process.env.NEXT_PUBLIC_AWS_S3_BASE_URL}/${res.fileName}`) @@ -208,7 +208,7 @@ export function useRefFiles() { formData.append('file', file) const res = await post({ - url: `${process.env.NEXT_PUBLIC_API_HOST_URL}/api/image/upload`, + url: `${Config().baseUrl}/api/image/upload`, data: formData, }) console.log('🚀 ~ handleUploadImageRefFile ~ res:', res) @@ -265,7 +265,7 @@ export function useRefFiles() { /** 캐드 도면 파일 업로드 */ const result = await post({ - url: `${process.env.NEXT_PUBLIC_API_HOST_URL}/api/image/cad`, + url: `${Config().baseUrl}/api/image/cad`, data: newFormData, }) console.log('🚀 ~ handleUploadConvertRefFile ~ result:', result)