From 8b932df38edd7c5a6b29808f270c94b7f5ccad2b Mon Sep 17 00:00:00 2001
From: myunsyeya <myunsyeya@ajou.ac.kr>
Date: Sun, 1 Dec 2024 15:38:21 +0900
Subject: [PATCH] chore: Mock on/off

---
 .env.development                       |  2 ++
 package-lock.json                      | 26 ++++++++++++++++++++++++++
 package.json                           |  5 +++--
 src/api/auth/axiosLogout.js            |  2 +-
 src/api/my/getMyPCs.js                 |  2 +-
 src/api/my/getRegistrationCode.js      |  2 +-
 src/api/my/registerNewPC.js            |  2 +-
 src/api/my/validateRegistrationCode.js |  2 +-
 src/api/parts/getPartById.js           |  2 +-
 src/api/parts/getRecommendedParts.js   |  2 +-
 src/index.js                           |  3 ++-
 ~env                                   |  4 ++--
 12 files changed, 42 insertions(+), 12 deletions(-)
 create mode 100644 .env.development

diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000..021fb10
--- /dev/null
+++ b/.env.development
@@ -0,0 +1,2 @@
+REACT_APP_NODE_ENV=development
+REACT_APP_API_URL=http://meanspec.enak.kr/api
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index f601d94..39aba90 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12,6 +12,7 @@
         "@testing-library/react": "^13.4.0",
         "@testing-library/user-event": "^13.5.0",
         "axios": "^1.7.8",
+        "env-cmd": "^10.1.0",
         "my-app": "file:",
         "react": "^18.3.1",
         "react-dom": "^18.3.1",
@@ -7732,6 +7733,31 @@
         "url": "https://github.com/fb55/entities?sponsor=1"
       }
     },
+    "node_modules/env-cmd": {
+      "version": "10.1.0",
+      "resolved": "https://registry.npmjs.org/env-cmd/-/env-cmd-10.1.0.tgz",
+      "integrity": "sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==",
+      "license": "MIT",
+      "dependencies": {
+        "commander": "^4.0.0",
+        "cross-spawn": "^7.0.0"
+      },
+      "bin": {
+        "env-cmd": "bin/env-cmd.js"
+      },
+      "engines": {
+        "node": ">=8.0.0"
+      }
+    },
+    "node_modules/env-cmd/node_modules/commander": {
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
+      "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==",
+      "license": "MIT",
+      "engines": {
+        "node": ">= 6"
+      }
+    },
     "node_modules/error-ex": {
       "version": "1.3.2",
       "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz",
diff --git a/package.json b/package.json
index 2524d65..b067dc5 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
     "@testing-library/react": "^13.4.0",
     "@testing-library/user-event": "^13.5.0",
     "axios": "^1.7.8",
+    "env-cmd": "^10.1.0",
     "my-app": "file:",
     "react": "^18.3.1",
     "react-dom": "^18.3.1",
@@ -15,14 +16,14 @@
     "web-vitals": "^2.1.4"
   },
   "scripts": {
-    "start": "react-app-rewired start",
+    "start": "env-cmd -f .env react-app-rewired start",
     "build": "react-app-rewired build",
     "test": "react-app-rewired test",
     "start-origin": "react-scripts start",
     "build-origin": "react-scripts build",
     "test-origin": "react-scripts test",
     "eject": "react-scripts eject",
-    "dev": "cross-env NODE_ENV=development react-app-rewired start"
+    "dev": "env-cmd -f .env.development react-app-rewired start"
   },
   "eslintConfig": {
     "extends": [
diff --git a/src/api/auth/axiosLogout.js b/src/api/auth/axiosLogout.js
index 733f4fe..8d35690 100644
--- a/src/api/auth/axiosLogout.js
+++ b/src/api/auth/axiosLogout.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL
+const API_URL = process.env.REACT_APP_API_URL
 
 const axiosLogout = async (tokenData) => {
   try {
diff --git a/src/api/my/getMyPCs.js b/src/api/my/getMyPCs.js
index bf6daff..cb43637 100644
--- a/src/api/my/getMyPCs.js
+++ b/src/api/my/getMyPCs.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL;
+const API_URL = process.env.REACT_APP_API_URL;
 
 const getMyPCs = async () => {
   try {
diff --git a/src/api/my/getRegistrationCode.js b/src/api/my/getRegistrationCode.js
index 0358821..2896ea6 100644
--- a/src/api/my/getRegistrationCode.js
+++ b/src/api/my/getRegistrationCode.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL;
+const API_URL = process.env.REACT_APP_API_URL;
 
 const getRegistrationCode = async () => {
   try {
diff --git a/src/api/my/registerNewPC.js b/src/api/my/registerNewPC.js
index 9638ec2..babfaa7 100644
--- a/src/api/my/registerNewPC.js
+++ b/src/api/my/registerNewPC.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL;
+const API_URL = process.env.REACT_APP_API_URL;
 
 const registerNewPC = async (parts) => {
   try {
diff --git a/src/api/my/validateRegistrationCode.js b/src/api/my/validateRegistrationCode.js
index 8257fac..6d3a157 100644
--- a/src/api/my/validateRegistrationCode.js
+++ b/src/api/my/validateRegistrationCode.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL;
+const API_URL = process.env.REACT_APP_API_URL;
 
 const validateRegistrationCode = async (code) => {
   try {
diff --git a/src/api/parts/getPartById.js b/src/api/parts/getPartById.js
index 460ab39..0b15dc2 100644
--- a/src/api/parts/getPartById.js
+++ b/src/api/parts/getPartById.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL;
+const API_URL = process.env.REACT_APP_API_URL;
 
 const getPartById = async (partId) => {
   try {
diff --git a/src/api/parts/getRecommendedParts.js b/src/api/parts/getRecommendedParts.js
index 94f1b64..84d08d6 100644
--- a/src/api/parts/getRecommendedParts.js
+++ b/src/api/parts/getRecommendedParts.js
@@ -1,6 +1,6 @@
 import axios from "axios";
 
-const API_URL = process.env.REACT_APP_BACKEND_URL;
+const API_URL = process.env.REACT_APP_API_URL;
 
 const getRecommendedParts = async (filters, sort, limit = 100, page = 1) => {
   try {
diff --git a/src/index.js b/src/index.js
index 499ae45..205f21b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,9 +4,10 @@ import './index.css';
 import App from './App';
 import { worker } from './mocks/browser'
 
-if (process.env.NODE_ENV === 'development') {
+if (process.env.REACT_APP_NODE_ENV === 'development') {
   if (worker) {
       worker.start();
+      console.log("-------------------MSW--------------------------")
   } else {
       console.error('Mock Service Worker is not initialized.');
   }
diff --git a/~env b/~env
index cc53760..8615376 100644
--- a/~env
+++ b/~env
@@ -1,4 +1,4 @@
 
-REACT_APP_NODE_ENV=development
+REACT_APP_NODE_ENV=developments
 REACT_APP_FRONTEND_URL=
-REACT_APP_BACKEND_URL=
\ No newline at end of file
+REACT_APP_API_URL=
\ No newline at end of file
-- 
GitLab