43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import axios from "axios";
|
|
import router from "@/router/index";
|
|
|
|
const $api = axios.create({
|
|
baseURL: 'http://localhost:10325/api/',
|
|
timeout: 300000,
|
|
withCredentials : true
|
|
})
|
|
|
|
/**
|
|
* Default Content-Type : json
|
|
* form 사용 시 옵션에 { isFromDate : true } 추가
|
|
*/
|
|
$api.interceptors.request.use(
|
|
function (config) {
|
|
|
|
let contentType = 'application/json';
|
|
|
|
if (config.isFormData) contentType = 'multipart/form-data';
|
|
|
|
config.headers['Content-Type'] = contentType;
|
|
config.headers['X-Requested-With'] = 'XMLHttpRequest';
|
|
|
|
return config;
|
|
}, function (error) {
|
|
// 요청 오류가 있는 작업 수행
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
// 응답 인터셉터 추가하기
|
|
$api.interceptors.response.use(
|
|
function (response) {
|
|
// 2xx 범위에 있는 상태 코드는 이 함수를 트리거 합니다.
|
|
// 응답 데이터가 있는 작업 수행
|
|
return response;
|
|
}, function (error) {
|
|
// 2xx 외의 범위에 있는 상태 코드는 이 함수를 트리거 합니다.
|
|
// 응답 오류가 있는 작업 수행
|
|
return Promise.reject(error);
|
|
});
|
|
export default $api;
|