Skip to content

Commit

Permalink
hotfix: api 분리 (#356)
Browse files Browse the repository at this point in the history
* hotfix: response 분리

* chore: 프론트 yml 파일 변경
  • Loading branch information
GC-Park authored Aug 17, 2023
1 parent 63227b1 commit 39c01e4
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 34 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/fe-merge-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
workflow_dispatch:

pull_request:
branches: [ develop ]
types: [ closed ]
branches: [develop]
types: [closed]
paths: frontend/**

permissions:
Expand All @@ -23,13 +23,18 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: "frontend"
cache: 'npm'
cache-dependency-path: 'frontend'

- name: Install npm
run: npm install
working-directory: frontend

- name: 테스트 환경변수 설정
run: |
echo "REACT_APP_API_DEFAULT_DEV=${{ secrets.REACT_APP_API_DEFAULT_DEV }}" >> $GITHUB_ENV
echo "REACT_APP_API_DEFAULT_PROD=${{ secrets.REACT_APP_API_DEFAULT_PROD }}" >> $GITHUB_ENV
- name: Build project
run: npm run build
working-directory: frontend
Expand All @@ -41,7 +46,7 @@ jobs:
path: frontend/dist

deploy:
runs-on: [ self-hosted, dev ]
runs-on: [self-hosted, dev]
needs: build-and-upload

if: github.event.pull_request.merged
Expand Down Expand Up @@ -70,5 +75,3 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()


13 changes: 9 additions & 4 deletions .github/workflows/fe-merge-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

pull_request:
branches: [ main ]
branches: [main]
types: [closed]
paths: frontend/**

Expand All @@ -23,13 +23,18 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
cache-dependency-path: "frontend"
cache: 'npm'
cache-dependency-path: 'frontend'

- name: Install npm
run: npm install
working-directory: frontend

- name: 테스트 환경변수 설정
run: |
echo "REACT_APP_API_DEFAULT_DEV=${{ secrets.REACT_APP_API_DEFAULT_DEV }}" >> $GITHUB_ENV
echo "REACT_APP_API_DEFAULT_PROD=${{ secrets.REACT_APP_API_DEFAULT_PROD }}" >> $GITHUB_ENV
- name: Build project
run: npm run build
working-directory: frontend
Expand All @@ -41,7 +46,7 @@ jobs:
path: frontend/dist

deploy:
runs-on: [ self-hosted, prod]
runs-on: [self-hosted, prod]
needs: build-and-upload

if: github.event.pull_request.merged
Expand Down
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/

.env
dist/
build/
Expand Down
61 changes: 60 additions & 1 deletion frontend/package-lock.json

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

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"babel-plugin-styled-components": "^2.1.4",
"chromatic": "^6.19.9",
"cypress": "^12.17.4",
"dotenv": "^16.3.1",
"dotenv-webpack": "^8.0.1",
"eslint": "^8.44.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.8.0",
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/apis/getApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface Headers {
'Content-Type': string;
[key: string]: string;
}

export const getApi = async <T>(
type: 'tMap' | 'default' | 'login',
url: string,
Expand All @@ -18,21 +17,17 @@ export const getApi = async <T>(
const headers: Headers = {
'Content-Type': 'application/json',
};

if (userToken) {
headers['Authorization'] = `Bearer ${userToken}`;
}

const response = await fetch(apiUrl, {
method: 'GET',
headers: headers,
});

const responseData: T = await response.json();
if (response.status >= 400) {
//todo: status 상태별로 로그인 토큰 유효 검증
throw new Error('API 요청에 실패했습니다.');
}

return responseData;
};
4 changes: 0 additions & 4 deletions frontend/src/apis/postApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ interface Headers {
'Content-Type': string;
[key: string]: string;
}

export const postApi = async (url: string, data?: {}, contentType?: string) => {
const userToken = localStorage.getItem('userToken');
const headers: Headers = {
'Content-Type': `${contentType || 'application/json'}`,
};

if (userToken) {
headers['Authorization'] = `Bearer ${userToken}`;
}
Expand All @@ -23,11 +21,9 @@ export const postApi = async (url: string, data?: {}, contentType?: string) => {
headers: headers,
body: JSON.stringify(data),
});

if (response.status >= 400) {
//todo: status 상태별로 로그인 토큰 유효 검증
throw new Error('API 요청에 실패했습니다.');
}

return response;
};
4 changes: 0 additions & 4 deletions frontend/src/apis/putApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface Headers {
'Content-Type': string;
[key: string]: string;
}

export const putApi = async (
url: string,
data: { name: string; images: string[]; description: string },
Expand All @@ -16,7 +15,6 @@ export const putApi = async (
const headers: Headers = {
'Content-Type': 'application/json',
};

if (userToken) {
headers['Authorization'] = `Bearer ${userToken}`;
}
Expand All @@ -26,10 +24,8 @@ export const putApi = async (
headers: headers,
body: JSON.stringify(data),
});

if (response.status >= 400) {
throw new Error('API 요청에 실패했습니다.');
}

return response;
};
11 changes: 3 additions & 8 deletions frontend/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { ProvidePlugin, EnvironmentPlugin } = require('webpack');
const dotenv = require('dotenv');

// Load environment variables from '.env' file
const env = dotenv.config().parsed || {};
const Dotenv = require('dotenv-webpack');

module.exports = {
entry: {
Expand All @@ -23,10 +20,8 @@ module.exports = {
React: 'react',
process: 'process/browser.js',
}),
new EnvironmentPlugin({
REACT_APP_API_DEFAULT_DEV: env.REACT_APP_API_DEFAULT_DEV,
REACT_APP_API_DEFAULT_PROD: env.REACT_APP_API_DEFAULT_PROD,
}),

new Dotenv(),
],
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
Expand Down

0 comments on commit 39c01e4

Please sign in to comment.