Skip to content

Commit

Permalink
[feat] api 호스트 주소 env 파일을 통해 호출 (#64)
Browse files Browse the repository at this point in the history
* feat: 환경변수를 통한 api 주소 호출

* feat: environment.d.ts 추가

* chore: github action 실행 시 env 생성
  • Loading branch information
hwookim authored Jan 26, 2023
1 parent 55fbea3 commit 9ee2354
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
API_HOSTNAME=localhost
API_PORT=3000
API_VERSION=v1

API_URL=http://$API_HOSTNAME:$API_PORT/api/$API_VERSION
NEXT_PUBLIC_API_URL=$API_URL
15 changes: 15 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ jobs:
- name: Install dependencies
run: npm install

- name: Generate Environment Variables File for Production
run: |
echo "API_HOSTNAME=$API_HOSTNAME" >> .env
echo "API_PORT=$API_PORT" >> .env
echo "API_VERSION=$API_VERSION" >> .env
echo "API_URL=$API_URL" >> .env
echo "NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL" >> .env
env:
API_HOSTNAME: ${{ secrets.API_HOSTNAME }}
API_PORT: ${{ secrets.API_PORT }}
API_VERSION: ${{ secrets.API_VERSION }}
API_URL: ${{ secrets.API_URL }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}


- name: Publish to Chromatic
uses: chromaui/action@v1
with:
Expand Down
12 changes: 4 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel
Expand Down Expand Up @@ -96,12 +94,6 @@ yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# Local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# Vercel
.vercel

Expand Down Expand Up @@ -268,3 +260,7 @@ build-storybook.log
# End of https://www.toptal.com/developers/gitignore/api/storybookjs

.idea

.env
.env.*
!.env.sample
5 changes: 5 additions & 0 deletions environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace NodeJS {
export interface ProcessEnv {
readonly NEXT_PUBLIC_API_URL: string;
}
}
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"jest-environment-jsdom": "^29.3.1",
"msw": "^0.49.1",
"msw-storybook-addon": "^1.6.3",
"next-env": "^1.1.1",
"prettier": "^2.7.1",
"start-server-and-test": "^1.14.0",
"storybook-addon-next-router": "^4.0.2",
Expand Down
3 changes: 1 addition & 2 deletions src/configs/axios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from 'axios';

// TODO-GYU: 배포시 실제 API 로 변경되는 로직 추가
export const BASE_URL = 'http://localhost:3000/api/v1';
export const BASE_URL = process.env.NEXT_PUBLIC_API_URL;

export const initAxiosConfig = () => {
axios.defaults.baseURL = BASE_URL ?? '';
Expand Down

0 comments on commit 9ee2354

Please sign in to comment.