Skip to content

Commit

Permalink
feat: api 모듈화 (#23)
Browse files Browse the repository at this point in the history
- axios를 설치했습니다.
- axios 인스턴스를 생성했습니다.
- authAPI는 로그인 구현과 함께 수정하겠습니다.
  • Loading branch information
jeewonMoon authored Jul 29, 2024
1 parent e0b1ee5 commit 2bd3e93
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/apis/api/course.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {baseAPI} from '../utils/instance';

export const getCourseList = async (body: object) => {
try {
const {data} = await baseAPI.get('/schedules/search', body);
return data;
} catch (error) {
console.log('get course list fail: ', error);
}
};
20 changes: 20 additions & 0 deletions src/apis/utils/instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from 'axios';

const baseURL = import.meta.env.VITE_BASE_URL;

export const baseAPI = axios.create({
baseURL: baseURL,
headers: {
'Content-Type': 'application/json',
},
withCredentials: true,
});

// 토큰 받아오는 작업 필요
export const authAPI = axios.create({
baseURL: baseURL,
headers: {
// Authorization: `Bearer ${token}`,
},
withCredentials: true,
});
2 changes: 1 addition & 1 deletion src/pages/index/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Box = styled.div`
`;

const Main = styled.div`
width: 100%;
width: calc(100% - 23rem);
`;

const Article = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/styles/GlobalStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const GlobalStyle = createGlobalStyle`
}
thead {
position: sticky;
top: 0;
top: -1px;
}
`;

Expand Down
15 changes: 8 additions & 7 deletions tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"baseUrl": "./src",
"paths": {
"@components/*": ["src/components/*"],
"@pages/*": ["src/pages/*"],
"@assets/*": ["src/assets/*"],
"@store/*": ["src/store/*"],
"@plugins/*": ["src/plugins/*"],
"@/*": ["./src/*"]
"@/*": ["./*"],
"@components/*": ["components/*"],
"@pages/*": ["pages/*"],
"@assets/*": ["assets/*"],
"@store/*": ["store/*"],
"@plugins/*": ["plugins/*"],
"@apis/*": ["apis/*"]
},
"allowSyntheticDefaultImports": true
},
Expand Down
10 changes: 7 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite';
import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'node:path';
import {resolve} from 'node:path';
import svgr from 'vite-plugin-svgr';

// https://vitejs.dev/config/
Expand All @@ -12,7 +12,7 @@ export default defineConfig({
resolve: {
alias: [
{
find: '@src',
find: '@',
replacement: resolve(__dirname, './src'),
},
{
Expand All @@ -35,6 +35,10 @@ export default defineConfig({
find: '@plugins',
replacement: resolve(__dirname, './src/plugins'),
},
{
find: '@apis',
replacement: resolve(__dirname, './src/apis'),
},
],
},
});

0 comments on commit 2bd3e93

Please sign in to comment.