diff --git a/.env.development b/.env.development index 1a372fa..47cfa78 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,4 @@ +NEXT_PUBLIC_RUN_MODE=development # 모바일 디바이스로 로컬 서버 확인하려면 자신 IP 주소로 변경 # 다시 로컬에서 개발할때는 localhost로 변경 #route handler diff --git a/.env.localhost b/.env.localhost new file mode 100644 index 0000000..966e366 --- /dev/null +++ b/.env.localhost @@ -0,0 +1,18 @@ +NEXT_PUBLIC_RUN_MODE=local +# 모바일 디바이스로 로컬 서버 확인하려면 자신 IP 주소로 변경 +# 다시 로컬에서 개발할때는 localhost로 변경 +#route handler +NEXT_PUBLIC_API_URL=http://localhost:3000 + +#qsp 로그인 api +NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 + +#1:1문의 api +NEXT_PUBLIC_INQUIRY_API_URL=http://1.248.227.176:38080 + +#QPARTNER 로그인 api +DB_HOST=202.218.61.226 +DB_USER=readonly +DB_PASSWORD=aAjmFW12iHKW84l1 +DB_DATABASE=qpartners +DB_PORT=3306 \ No newline at end of file diff --git a/.env.production b/.env.production index 4c39e83..ce56225 100644 --- a/.env.production +++ b/.env.production @@ -1,5 +1,6 @@ +NEXT_PUBLIC_RUN_MODE=production #route handler -NEXT_PUBLIC_API_URL=http://172.30.1.35:3000 +NEXT_PUBLIC_API_URL=http://1.248.227.176:3000 #qsp 로그인 api NEXT_PUBLIC_QSP_API_URL=http://1.248.227.176:8120 diff --git a/package.json b/package.json index a57feca..d3be4d7 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,13 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev --turbopack", + "dev": "env-cmd -f .env.localhost next dev --turbopack", "build": "next build", "start": "next start", + "build:dev": "env-cmd -f .env.development next build", + "build:prod": "env-cmd -f .env.production next build", + "start:dev": "env-cmd -f .env.development next start", + "start:prod": "env-cmd -f .env.production next start", "lint": "next lint" }, "dependencies": { @@ -13,6 +17,7 @@ "@tanstack/react-query": "^5.71.0", "@tanstack/react-query-devtools": "^5.71.0", "axios": "^1.8.4", + "env-cmd": "^10.1.0", "iron-session": "^8.0.4", "lucide": "^0.503.0", "mssql": "^11.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d972d8..ee300e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: axios: specifier: ^1.8.4 version: 1.8.4 + env-cmd: + specifier: ^10.1.0 + version: 10.1.0 iron-session: specifier: ^8.0.4 version: 8.0.4 @@ -801,6 +804,10 @@ packages: resolution: {integrity: sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==} engines: {node: '>=16'} + commander@4.1.1: + resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} + engines: {node: '>= 6'} + cookie@0.7.2: resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==} engines: {node: '>= 0.6'} @@ -808,6 +815,10 @@ packages: core-js@3.41.0: resolution: {integrity: sha512-SJ4/EHwS36QMJd6h/Rg+GyR4A5xE0FSI3eZ+iBVpfqf1x0eTSg1smWLHrA+2jQThZSh97fmSgFSU8B61nxosxA==} + cross-spawn@7.0.6: + resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} + engines: {node: '>= 8'} + css-line-break@2.1.0: resolution: {integrity: sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==} @@ -866,6 +877,11 @@ packages: resolution: {integrity: sha512-ZSW3ma5GkcQBIpwZTSRAI8N71Uuwgs93IezB7mf7R60tC8ZbJideoDNKjHn2O9KIlx6rkGTTEk1xUCK2E1Y2Yg==} engines: {node: '>=10.13.0'} + env-cmd@10.1.0: + resolution: {integrity: sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==} + engines: {node: '>=8.0.0'} + hasBin: true + es-define-property@1.0.1: resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==} engines: {node: '>= 0.4'} @@ -1021,6 +1037,9 @@ packages: resolution: {integrity: sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==} engines: {node: '>=16'} + isexe@2.0.0: + resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + jiti@2.4.2: resolution: {integrity: sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==} hasBin: true @@ -1217,6 +1236,10 @@ packages: resolution: {integrity: sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==} engines: {node: '>=18'} + path-key@3.1.1: + resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} + engines: {node: '>=8'} + performance-now@2.1.0: resolution: {integrity: sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==} @@ -1324,6 +1347,14 @@ packages: resolution: {integrity: sha512-haPVm1EkS9pgvHrQ/F3Xy+hgcuMV0Wm9vfIBSiwZ05k+xgb0PkBQpGsAA/oWdDobNaZTH5ppvHtzCFbnSEwHVw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} + shebang-command@2.0.0: + resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} + engines: {node: '>=8'} + + shebang-regex@3.0.0: + resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} + engines: {node: '>=8'} + simple-swizzle@0.2.2: resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==} @@ -1423,6 +1454,11 @@ packages: resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} hasBin: true + which@2.0.2: + resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} + engines: {node: '>= 8'} + hasBin: true + zustand@5.0.3: resolution: {integrity: sha512-14fwWQtU3pH4dE0dOpdMiWjddcH+QzKIgk1cl8epwSE7yag43k/AD/m4L6+K7DytAOr9gGBe3/EXj9g7cdostg==} engines: {node: '>=12.20.0'} @@ -2070,11 +2106,19 @@ snapshots: commander@11.1.0: {} + commander@4.1.1: {} + cookie@0.7.2: {} core-js@3.41.0: optional: true + cross-spawn@7.0.6: + dependencies: + path-key: 3.1.1 + shebang-command: 2.0.0 + which: 2.0.2 + css-line-break@2.1.0: dependencies: utrie: 1.0.2 @@ -2123,6 +2167,11 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.2.1 + env-cmd@10.1.0: + dependencies: + commander: 4.1.1 + cross-spawn: 7.0.6 + es-define-property@1.0.1: {} es-errors@1.3.0: {} @@ -2297,6 +2346,8 @@ snapshots: dependencies: is-inside-container: 1.0.0 + isexe@2.0.0: {} + jiti@2.4.2: {} js-md4@0.3.2: {} @@ -2500,6 +2551,8 @@ snapshots: is-inside-container: 1.0.0 is-wsl: 3.1.0 + path-key@3.1.1: {} + performance-now@2.1.0: optional: true @@ -2622,6 +2675,12 @@ snapshots: '@img/sharp-win32-x64': 0.33.5 optional: true + shebang-command@2.0.0: + dependencies: + shebang-regex: 3.0.0 + + shebang-regex@3.0.0: {} + simple-swizzle@0.2.2: dependencies: is-arrayish: 0.3.2 @@ -2703,6 +2762,10 @@ snapshots: uuid@8.3.2: {} + which@2.0.2: + dependencies: + isexe: 2.0.0 + zustand@5.0.3(@types/react@19.0.12)(react@19.1.0): optionalDependencies: '@types/react': 19.0.12 diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 6322ec4..043fee6 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -5,9 +5,8 @@ import { useEffect, useReducer, useState } from 'react' import { useRouter } from 'next/navigation' import { useLocalStorage } from 'usehooks-ts' import { useQuery } from '@tanstack/react-query' -import { axiosInstance } from '@/libs/axios' import { useSessionStore } from '@/store/session' - +import { useAxios } from '@/hooks/useAxios' interface AccountState { loginId: string pwd: string @@ -24,6 +23,8 @@ export default function Login() { //로그인 상태 const [isLogin, setIsLogin] = useState(false) + const { axiosInstance } = useAxios() + const { session, setSession } = useSessionStore() const [value, setValue, removeValue] = useLocalStorage<{ indivisualData: string }>('hanasysIndivisualState', { indivisualData: '' }) diff --git a/src/components/ui/common/Footer.tsx b/src/components/ui/common/Footer.tsx index 08cce69..2d20a63 100644 --- a/src/components/ui/common/Footer.tsx +++ b/src/components/ui/common/Footer.tsx @@ -1,6 +1,7 @@ 'use client' import Link from 'next/link' +import Config from '@/config/config.export' export default function Footer() { return ( @@ -11,6 +12,9 @@ export default function Footer() { PDF + {Config().mode} + {Config().baseUrl} + {process.env.NEXT_PUBLIC_API_URL} diff --git a/src/components/ui/common/Header.tsx b/src/components/ui/common/Header.tsx index bd92675..734f58f 100644 --- a/src/components/ui/common/Header.tsx +++ b/src/components/ui/common/Header.tsx @@ -13,14 +13,13 @@ import { useSessionStore } from '@/store/session' import { usePopupController } from '@/store/popupController' import { useTitle } from '@/hooks/useTitle' - -import { axiosInstance } from '@/libs/axios' - +import { useAxios } from '@/hooks/useAxios' import 'swiper/css' export default function Header() { const router = useRouter() const pathname = usePathname() + const { axiosInstance } = useAxios() const [value, setValue, removeValue] = useLocalStorage<{ indivisualData: string }>('hanasysIndivisualState', { indivisualData: '' }) const { sideNavIsOpen, setSideNavIsOpen } = useSideNavState() const { backBtn } = useHeaderStore() diff --git a/src/config/config.common.ts b/src/config/config.common.ts new file mode 100644 index 0000000..e99d9f0 --- /dev/null +++ b/src/config/config.common.ts @@ -0,0 +1,20 @@ +export declare namespace ICommonConfig { + export type Mode = 'local' | 'development' | 'production' + + export interface Params { + baseUrl: string + mode: Mode + } +} + +// local, development, production 과 관계없이 동일한 값으로 반환되는 부분은 해당 함수의 return 되는 부분만 수정하면 됩니다. (달라져야 하는 값이 아닌, 같은 값에 대해서는 local, development, production 파일을 모두 수정할 필요가 없어지게 됩니다.) +export default function getConfigs(params: ICommonConfig.Params) { + // local, development, production 마다 달라지는 값 + const { baseUrl, mode } = params + + // 공통으로 반환되는 구조 + return { + baseUrl, + mode, + } +} diff --git a/src/config/config.development.ts b/src/config/config.development.ts new file mode 100644 index 0000000..70765ec --- /dev/null +++ b/src/config/config.development.ts @@ -0,0 +1,13 @@ +import getConfigs from '@/config/config.common' + +// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 development 환경에 맞는 값을 지정합니다.) +const baseUrl = 'http://1.248.227.176:3000' +const mode = 'development' + +// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다. +const configDevelopment = getConfigs({ + baseUrl, + mode, +}) + +export default configDevelopment diff --git a/src/config/config.export.ts b/src/config/config.export.ts new file mode 100644 index 0000000..8948763 --- /dev/null +++ b/src/config/config.export.ts @@ -0,0 +1,19 @@ +import configDevelopment from './config.development' +import configLocal from './config.local' +import configProduction from './config.production' + +// 클라이언트에서는 이 함수를 사용하여 config 값을 참조합니다. +const Config = () => { + switch (process.env.NEXT_PUBLIC_RUN_MODE) { + case 'local': + return configLocal + case 'development': + return configDevelopment + case 'production': + return configProduction + default: + return configLocal + } +} + +export default Config diff --git a/src/config/config.local.ts b/src/config/config.local.ts new file mode 100644 index 0000000..ac02c97 --- /dev/null +++ b/src/config/config.local.ts @@ -0,0 +1,13 @@ +import getConfigs from '@/config/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.ts b/src/config/config.production.ts new file mode 100644 index 0000000..5b1db52 --- /dev/null +++ b/src/config/config.production.ts @@ -0,0 +1,13 @@ +import getConfigs from '@/config/config.common' + +// 환경마다 달라져야 할 변수, 값들을 정의합니다. (여기는 production 환경에 맞는 값을 지정합니다.) +const baseUrl = 'http://localhost.prod:3000' +const mode = 'production' + +// 환경마다 달라져야 할 값들을 getConfig 함수에 전달합니다. +const configProduction = getConfigs({ + baseUrl, + mode, +}) + +export default configProduction diff --git a/src/hooks/useAxios.ts b/src/hooks/useAxios.ts index ac59166..49c5ec0 100644 --- a/src/hooks/useAxios.ts +++ b/src/hooks/useAxios.ts @@ -1,11 +1,12 @@ import axios from 'axios' +import Config from '@/config/config.export' import { useSpinnerStore } from '@/store/spinnerStore' export const useAxios = () => { const { setIsShow } = useSpinnerStore() const axiosInstance = (url: string | null | undefined) => { - const baseURL = url || process.env.NEXT_PUBLIC_API_URL + const baseURL = url || Config().baseUrl const instance = axios.create({ baseURL, headers: { diff --git a/src/libs/tracking.ts b/src/libs/tracking.ts index 2f8833f..f06a3e7 100644 --- a/src/libs/tracking.ts +++ b/src/libs/tracking.ts @@ -1,7 +1,8 @@ -import { axiosInstance } from './axios' +import { useAxios } from '@/hooks/useAxios' export const tracking = async (params: { url: string; data: string }) => { const { url, data } = params + const { axiosInstance } = useAxios() const result = await axiosInstance(null).post('/api/tracking', { url, data,