From 63c524449a95f5675e23a1c17e596584cca538ed Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 18:48:02 +0900 Subject: [PATCH 1/7] =?UTF-8?q?refactor:=20api=20url=EC=9D=84=20window?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EB=B0=9B=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EA=B2=8C=20=EC=88=98=EC=A0=95=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/api/index.ts | 2 +- frontend/src/vite-env.d.ts | 8 +++++ frontend/vite.config.ts | 55 +++++++++++++++++++-------------- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/frontend/src/utils/api/index.ts b/frontend/src/utils/api/index.ts index a08c68e..8a509bf 100644 --- a/frontend/src/utils/api/index.ts +++ b/frontend/src/utils/api/index.ts @@ -1,7 +1,7 @@ import axios from 'axios'; const api = axios.create({ - baseURL: import.meta.env.VITE_API_URL, + baseURL: window.__API_URL__, }); export default api; diff --git a/frontend/src/vite-env.d.ts b/frontend/src/vite-env.d.ts index 083a5ec..9dbefe7 100644 --- a/frontend/src/vite-env.d.ts +++ b/frontend/src/vite-env.d.ts @@ -1,2 +1,10 @@ // eslint-disable-next-line spaced-comment /// + +export {}; + +declare global { + interface Window { + __API_URL__: string; + } +} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 7145f4e..989e763 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,29 +1,36 @@ import react from '@vitejs/plugin-react-swc'; import path from 'path'; -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; -export default defineConfig({ - resolve: { - alias: [ - { - find: '@', - replacement: path.resolve(__dirname, 'src'), - }, - { - find: '@style', - replacement: path.resolve(__dirname, 'styled-system'), - }, - ], - }, - build: { - rollupOptions: { - output: { - inlineDynamicImports: true, +export default () => { + const env = loadEnv('', process.cwd(), 'APP'); + console.log(env); + return defineConfig({ + resolve: { + alias: [ + { + find: '@', + replacement: path.resolve(__dirname, 'src'), + }, + { + find: '@style', + replacement: path.resolve(__dirname, 'styled-system'), + }, + ], + }, + build: { + rollupOptions: { + output: { + inlineDynamicImports: true, + }, }, }, - }, - worker: { - format: 'es', - }, - plugins: [react()], -}); + worker: { + format: 'es', + }, + plugins: [react()], + define: { + __API_URL__: JSON.stringify(env.APP_API_URL), + }, + }); +}; From 6cadc329264d71de0ee0dcb9f8bf3f59e60a889c Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 18:54:56 +0900 Subject: [PATCH 2/7] refactor: add debug code --- frontend/src/apis/competitionList/index.ts | 1 + frontend/vite.config.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/apis/competitionList/index.ts b/frontend/src/apis/competitionList/index.ts index 7850910..622c866 100644 --- a/frontend/src/apis/competitionList/index.ts +++ b/frontend/src/apis/competitionList/index.ts @@ -5,6 +5,7 @@ import { Competition } from './types'; export const fetchCompetitionList = async (): Promise => { try { const response = await api.get('/competitions'); + console.log(response); return response.data; } catch (error) { console.error('Error fetching competitions:', (error as Error).message); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 989e763..69e821c 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,7 +4,7 @@ import { defineConfig, loadEnv } from 'vite'; export default () => { const env = loadEnv('', process.cwd(), 'APP'); - console.log(env); + return defineConfig({ resolve: { alias: [ From 16079ddd7018ad865935bd6c6d25e0ed6843218b Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 18:57:37 +0900 Subject: [PATCH 3/7] =?UTF-8?q?chore:=20error=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/apis/competitionList/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/apis/competitionList/index.ts b/frontend/src/apis/competitionList/index.ts index 622c866..da07c85 100644 --- a/frontend/src/apis/competitionList/index.ts +++ b/frontend/src/apis/competitionList/index.ts @@ -5,9 +5,9 @@ import { Competition } from './types'; export const fetchCompetitionList = async (): Promise => { try { const response = await api.get('/competitions'); - console.log(response); return response.data; } catch (error) { + console.log(error); console.error('Error fetching competitions:', (error as Error).message); throw error; } From ce19ab4cde0c101fa178a1bc157ed86c0a3d2b3a Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 19:01:48 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20=EB=94=94=EB=B2=84=EA=B9=85=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/apis/competitionList/index.ts | 2 +- frontend/src/utils/api/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/apis/competitionList/index.ts b/frontend/src/apis/competitionList/index.ts index da07c85..063caf5 100644 --- a/frontend/src/apis/competitionList/index.ts +++ b/frontend/src/apis/competitionList/index.ts @@ -5,9 +5,9 @@ import { Competition } from './types'; export const fetchCompetitionList = async (): Promise => { try { const response = await api.get('/competitions'); + return response.data; } catch (error) { - console.log(error); console.error('Error fetching competitions:', (error as Error).message); throw error; } diff --git a/frontend/src/utils/api/index.ts b/frontend/src/utils/api/index.ts index 8a509bf..a613601 100644 --- a/frontend/src/utils/api/index.ts +++ b/frontend/src/utils/api/index.ts @@ -1,5 +1,6 @@ import axios from 'axios'; +console.log(333, window.__API_URL__); const api = axios.create({ baseURL: window.__API_URL__, }); From bcee928b1cf5b0eb71340fc2eebc2a3e3290e867 Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 19:04:05 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20=EB=94=94=EB=B2=84=EA=B9=85=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/vite.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 69e821c..7fe2bfb 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,7 +4,7 @@ import { defineConfig, loadEnv } from 'vite'; export default () => { const env = loadEnv('', process.cwd(), 'APP'); - + console.log(env, env.APP_API_URL); return defineConfig({ resolve: { alias: [ From 515d59dd88cbc0b90a86ae2dbe69a8914f6e3a69 Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 19:09:59 +0900 Subject: [PATCH 6/7] =?UTF-8?q?refactor:=20=EB=94=94=EB=B2=84=EA=B9=85?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/vite.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 7fe2bfb..965abc0 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,7 +4,7 @@ import { defineConfig, loadEnv } from 'vite'; export default () => { const env = loadEnv('', process.cwd(), 'APP'); - console.log(env, env.APP_API_URL); + console.log(env, process.env, env.APP_API_URL); return defineConfig({ resolve: { alias: [ From 944f55a8983dc60ec481410cf290d46ba387a82f Mon Sep 17 00:00:00 2001 From: dev2820 Date: Tue, 28 Nov 2023 19:15:29 +0900 Subject: [PATCH 7/7] =?UTF-8?q?refactor:=20VITE=5FAPI=5FURL=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B5=EA=B7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/api/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/api/index.ts b/frontend/src/utils/api/index.ts index a613601..130752c 100644 --- a/frontend/src/utils/api/index.ts +++ b/frontend/src/utils/api/index.ts @@ -1,8 +1,9 @@ import axios from 'axios'; -console.log(333, window.__API_URL__); +console.log(333, import.meta.env.VITE_API_URL); + const api = axios.create({ - baseURL: window.__API_URL__, + baseURL: import.meta.env.VITE_API_URL, }); export default api;