Skip to content

Commit

Permalink
Merge pull request #120 from pknu-wap/refactor/#119-env_setup
Browse files Browse the repository at this point in the history
[feature] 서버 주소 환경변수로 처리
  • Loading branch information
oesnuj authored Dec 21, 2024
2 parents 113a033 + d0d7f18 commit aadb8cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion client/src/api/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import axios from 'axios';
import Cookies from 'js-cookie';

const apiBaseUrl = process.env.REACT_APP_API_BASE_URL;

// Axios 클라이언트 생성
const apiClient = axios.create({
baseURL: 'http://34.64.179.51:8080/api', // 기본 API URL 설정
baseURL: apiBaseUrl, // 기본 API URL 설정
});

// 요청 인터셉터
Expand Down
5 changes: 4 additions & 1 deletion client/src/api/logIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface RegisterResponse {
data: LoginData;
}

// 환경변수에서 API URL 가져오기
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL;

// 토큰 가져오기 함수 추가
export const getAccessToken = (): string | null => {
return localStorage.getItem('accessToken');
Expand Down Expand Up @@ -54,7 +57,7 @@ export const logIn = async (
try {
// 로그인 API 호출
const response = await axios.post<RegisterResponse>(
'http://34.64.179.51:8080/auth/admins/login',
`${API_BASE_URL}/auth/admins/login`, // 환경변수를 사용한 API URL
{
name: name,
password: password,
Expand Down
8 changes: 6 additions & 2 deletions client/src/api/signUp.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import axios, {AxiosResponse} from 'axios';

// 환경변수에서 API URL 가져오기
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL;

// 회원가입 함수
export const signUp = (
name: string,
password: string,
email: string,
): Promise<AxiosResponse | null> => {
return axios
.post('http://34.64.179.51:8080/auth/admins/register', {
.post(`${API_BASE_URL}/auth/admins/register`, {
name: name,
password: password,
email: email,
Expand All @@ -15,7 +19,7 @@ export const signUp = (
return res;
})
.catch(error => {
console.log('Failed to register admin:', error);
console.error('Failed to register admin:', error);
return null;
});
};

0 comments on commit aadb8cd

Please sign in to comment.