add game,home pages

This commit is contained in:
wzdwc
2020-04-17 23:38:34 +08:00
parent a947d75f3d
commit 9b4944f23d
72 changed files with 887 additions and 197 deletions
+33 -26
View File
@@ -1,26 +1,33 @@
import axios, { AxiosRequestConfig, Method } from 'axios';
import cookie from 'js-cookie';
const request = async ({ method = 'post' as Method, url = '', body= {}, timeout = 8000 }) => {
const origin = '';
if (!url) {
return Promise.reject('Request url is null!');
}
const token = cookie.get('game_token');
const headers = {
Authorization: `Bearer ${token}`,
};
url = `${origin}/${url}`;
const option: AxiosRequestConfig = {
url,
method,
timeout,
withCredentials: true,
headers,
};
try {
return await axios(option);
} catch (e) {
throw e;
}
};
export default request;
import axios, {AxiosRequestConfig, Method} from 'axios';
import cookie from 'js-cookie';
const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => {
const origin = 'http://127.0.0.1:7001/node';
if (!url) {
return Promise.reject('Request url is null!');
}
const token = cookie.get('token');
const headers = {
Authorization: `Bearer ${token}`,
};
url = `${origin}${url}`;
const option: AxiosRequestConfig = {
url,
method,
timeout,
data: body,
withCredentials: true,
headers,
};
try {
const result = await axios(option);
if (result.data.code === '000000') {
return result.data;
} else {
throw result.data;
}
} catch (e) {
throw e;
}
};
export default request;