-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApi.js
65 lines (63 loc) · 1.65 KB
/
Api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable import/no-anonymous-default-export */
import axios from 'axios';
// 로컬 테스트용, 실제 배포서버용 api주소
const reqUrl = 'http://192.168.219.104:8000';
// const reqUrl = 'https://port-0-humanstats-5x7y2mlh8rjlfi.sel4.cloudtype.app';
export default {
// POST. 점수 저장 요청 함수
saveScore(gameName, userId, score, isRegistered, setIsRegistered) {
if (userId === null) {
alert('로그인후 시도해주세요.');
return;
}
if (isRegistered === true) {
alert('이미 등록되었습니다.');
return;
}
axios
.post(`${reqUrl}/postScore/`, {
gameName: gameName,
id: userId,
score: score,
})
.then(function (Response) {
setIsRegistered(true);
alert('등록완료!');
})
.catch((Error) => console.log(Error));
},
// GET. 각 게임 페이지 진입시 랭킹 정보 얻어오는 함수
async getRanking(gameName) {
try {
const response = await axios.get(`${reqUrl}/rank/${gameName}`);
return response.data;
} catch (error) {
console.log(error);
return null;
}
},
// POST. 로그인 요청 함수
async requestLogin(id, pw) {
try {
const response = axios.post(`${reqUrl}/#/`, {
id: id,
pw: pw,
});
return response;
} catch (error) {
console.log(error);
}
},
// POST. 회원가입 요청 함수
async request#(id, pw) {
try {
const response = axios.post(`${reqUrl}/#/`, {
id: id,
pw: pw,
});
return response;
} catch (error) {
console.log(error);
}
},
};