Skip to content

Commit

Permalink
➕ Add: 프록시 미들웨어 추가
Browse files Browse the repository at this point in the history
- React-Script 5.0에서 package.json 파일에 proxy 속성 추가 시 오류 발생
- 참고 이슈 : facebook/create-react-app#11762
  • Loading branch information
romantech committed Mar 11, 2022
1 parent 1b69bbf commit e91a2aa
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "shopping-insight-graph",
"version": "0.1.0",
"private": true,
"proxy": "https://openapi.naver.com",
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@redux-devtools/extension": "^3.2.2",
Expand Down Expand Up @@ -55,6 +54,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.3",
"eslint-plugin-react-hooks": "^4.3.0",
"http-proxy-middleware": "^2.0.3",
"prettier": "2.5.1"
}
}
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, { AxiosPromise, CancelTokenSource } from 'axios';

axios.defaults.baseURL = 'v1/datalab/';
axios.defaults.baseURL = 'v1/datalab';
axios.defaults.headers.common['X-Naver-Client-Id'] =
process.env.REACT_APP_CLIENT_ID;
axios.defaults.headers.common['X-Naver-Client-Secret'] =
Expand Down
1 change: 1 addition & 0 deletions src/components/FormOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default function FormOptions(): JSX.Element {

const StyledWrapper = styled.section`
${FlexCenterColumn};
padding: 1rem;
width: 100%;
gap: 2rem;
h1 {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SingleDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export default function SingleDatePicker({

const onChangeHandler = (date: moment.Moment) => {
const isValid =
date?.isAfter(startDate || '2017-08') &&
date?.isAfter(startDate || '2017-07-31') &&
date?.isBefore(endDate || moment());

if (!isValid && date) {
notification.error({
message:
'2017년 8월부터 오늘까지만 조회할 수 있습니다. 다시 선택해주세요',
'2017년 8월부터 오늘까지만 조회할 수 있어요. 다시 선택해주세요',
});
}
callback(paramKey, isValid ? date.format('YYYY-MM-DD') : '');
Expand Down
6 changes: 3 additions & 3 deletions src/modules/insightData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ type InsightDataAction =
interface InsightDataState {
loading: boolean;
error: Error | null;
results: Result[];
response: Result[];
}

// 기본값
const initialState: InsightDataState = {
loading: false,
error: null,
results: [],
response: [],
};

export const GET_DATA_REQUEST = 'insightData/GET_DATA_REQUEST';
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function reducer(
...state,
loading: false,
error: null,
results: action.payload.results,
response: action.payload.results,
};
case GET_DATA_FAILED:
return {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/selectedParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const initialState: RequestParams = {
startDate: moment().subtract(7, 'days').format('YYYY-MM-DD'),
endDate: moment().format('YYYY-MM-DD'),
timeUnit: 'date',
category: '50000008',
category: '50000003',
keyword: '',
device: '',
gender: '',
Expand Down
7 changes: 3 additions & 4 deletions src/pages/ShoppingInsight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import styled from 'styled-components/macro';
import { useSelector } from 'react-redux';
import { Empty, Spin } from 'antd';
import FormOptions from '../components/FormOptions';
import Chart from '../components/Chart';
import { RootState } from '../modules';
import { FlexCenterRow } from '../styles/commonStyles';
import Chart from '../components/Chart';

export default function ShoppingInsight(): JSX.Element {
const { loading, results, error } = useSelector(
const { loading, response, error } = useSelector(
(state: RootState) => state.insightData,
);

const data = results[0]?.data;

const data = response[0]?.data;
return (
<StyledInsightWrapper>
<StyledFormOptions>
Expand Down
11 changes: 11 additions & 0 deletions src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line import/no-extraneous-dependencies,@typescript-eslint/no-var-requires
const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function (app) {
app.use(
createProxyMiddleware('/v1/datalab', {
target: 'https://openapi.naver.com',
changeOrigin: true,
}),
);
};

0 comments on commit e91a2aa

Please sign in to comment.