Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 55 additions & 18 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.0.0",
"type": "module",
"dependencies": {
"axios": "^1.12.2",
"qs": "^6.14.0",
"react": "^18.3.1",
"react-datepicker": "^4.25.0",
Expand Down Expand Up @@ -35,4 +36,4 @@
"test:run": "vitest run"
},
"proxy": "http://localhost:8080"
}
}
9 changes: 9 additions & 0 deletions src/api/axiosInstance/axiosInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import axios from "axios";
import { SERVER_URL } from "../../config";

const api = axios.create({
baseURL: SERVER_URL,
withCredentials: true,
});

export default api;
8 changes: 8 additions & 0 deletions src/api/axiosInstance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { requestInterceptor } from "./interceptor/requestInterceptor";
import { responseInterceptor } from "./interceptor/responseInterceptor";
import axiosInstance from "./axiosInstance";

axiosInstance.interceptors.request.use(requestInterceptor);
axiosInstance.interceptors.response.use(responseInterceptor);

export default axiosInstance;
16 changes: 16 additions & 0 deletions src/api/axiosInstance/interceptor/requestInterceptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getSessionItem } from "@/utils/storage";

export const requestInterceptor = (config) => {
const sessionUser = getSessionItem("loginUser");
const jToken = getSessionItem("jToken");

if (sessionUser?.id) {
config.headers.Authorization = jToken;
}

return config;
};

export const requestInterceptorError = (error) => {
throw error;
};
26 changes: 26 additions & 0 deletions src/api/axiosInstance/interceptor/responseInterceptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import URL from "@/constants/url";
import CODE from "@/constants/code";
import { setSessionItem } from "@/utils/storage";

export const responseInterceptor = (response) => {
const resp = response.data;

if (Number(resp.resultCode) === Number(CODE.RCV_ERROR_AUTH)) {
alert("Login Alert");
setSessionItem("loginUser", { id: "" });
window.location.href = URL.LOGIN;
throw new Error("인증 오류");
}

return resp;
};

export const responseInterceptorError = (error) => {
console.error("There was an error!", error);

if (error.message.includes("Network Error")) {
alert("서버와의 연결이 원활하지 않습니다. 서버를 확인하세요.");
}

throw error;
};
64 changes: 0 additions & 64 deletions src/api/egovFetch.jsx

This file was deleted.

25 changes: 25 additions & 0 deletions src/api/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import axiosInstance from "./axiosInstance";

// GET
export const getApi = async (url, params = {}) => {
const res = await axiosInstance.get(url, { params });
return res;
};

// POST
export const postApi = async (url, body = {}) => {
const res = await axiosInstance.post(url, body);
return res;
};

// PUT
export const putApi = async (url, body = {}) => {
const res = await axiosInstance.put(url, body);
return res;
};

// DELETE
export const deleteApi = async (url, params = {}) => {
const res = await axiosInstance.delete(url, { params });
return res;
};
6 changes: 6 additions & 0 deletions src/api/services/EgovAdminBoardList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getApi } from "../http";

export const fetchAdminBoardList = (srchCnd) => {
const retrieveListURL = "/bbsMaster";
return getApi(retrieveListURL, { srchCnd });
};
6 changes: 6 additions & 0 deletions src/api/services/EgovHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getApi } from "../http";
export const logOut = () => {
// 로그인 정보 존재할 때
const logOutUrl = "/auth/logout";
return getApi(logOutUrl);
};
6 changes: 6 additions & 0 deletions src/api/services/EgovLoginContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { postApi } from "../http";

export const login = (userInfo) => {
const loginUrl = "/auth/login-jwt";
return postApi(loginUrl, userInfo);
};
5 changes: 5 additions & 0 deletions src/api/services/EgovMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getApi } from "../http";
export const fetchMainPage = () => {
const retrieveListURL = "/mainPage";
return getApi(retrieveListURL);
};
20 changes: 0 additions & 20 deletions src/api/services/mainPage.js

This file was deleted.

Loading