Skip to content

Commit e2ace22

Browse files
committed
feat: support API endpoint from env
1 parent 8925e8d commit e2ace22

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REACT_APP_API_ENDPOINT=http://localhost:3000

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
build/
33
.idea
4+
.env

src/api/BenchmarkServices.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class BenchmarkServices {
99
difficulty: string,
1010
): Promise<benchmarkModel> {
1111
const res: AxiosResponse<benchmarkModel> = await axios.post(
12-
'http://localhost:3000/benchmarks',
12+
`${process.env.REACT_APP_API_ENDPOINT}/benchmarks`,
1313
{
1414
title,
1515
subject,
@@ -26,14 +26,16 @@ export class BenchmarkServices {
2626
}
2727

2828
static async getAllBenchmarks(): Promise<benchmarkModel[]> {
29-
return axios.get('http://localhost:3000/benchmarks').then((response) => {
30-
return response.data;
31-
});
29+
return axios
30+
.get(`${process.env.REACT_APP_API_ENDPOINT}/benchmarks`)
31+
.then((response) => {
32+
return response.data;
33+
});
3234
}
3335

3436
static async getBenchmarkById(id: string): Promise<benchmarkModel> {
3537
return axios
36-
.get('http://localhost:3000/benchmarks/' + id)
38+
.get(`${process.env.REACT_APP_API_ENDPOINT}/benchmarks/${id}`)
3739
.then((response) => {
3840
return response.data;
3941
});

src/api/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
22

33
const login = async (username: string, password: string): Promise<string> => {
44
const res: AxiosResponse<{ access_token: string }> = await axios.post(
5-
'http://localhost:3000/auth/login',
5+
`${process.env.REACT_APP_API_ENDPOINT}/auth/login`,
66
{
77
username,
88
password,

src/api/submissions.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ function useProcessInterval({
1616

1717
// 1: Handle code submission
1818
async function createJob(code: string) {
19-
const response = await fetch('http://localhost:3000/submissions', {
20-
method: 'POST',
21-
headers: {
22-
'Content-Type': 'application/json',
23-
Authorization: `Bearer ${token}`,
19+
const response = await fetch(
20+
`${process.env.REACT_APP_API_ENDPOINT}/submissions`,
21+
{
22+
method: 'POST',
23+
headers: {
24+
'Content-Type': 'application/json',
25+
Authorization: `Bearer ${token}`,
26+
},
27+
body: JSON.stringify({
28+
language: 'cpython3',
29+
code: code,
30+
}),
2431
},
25-
body: JSON.stringify({
26-
language: 'cpython3',
27-
code: code,
28-
}),
29-
});
32+
);
3033
return await response.json();
3134
}
3235

@@ -50,11 +53,14 @@ function useProcessInterval({
5053
['processProgress', token, processId],
5154
async () => {
5255
const res: AxiosResponse<{ status: string; output: string }> =
53-
await axios.get(`http://localhost:3000/submissions/${processId}`, {
54-
headers: {
55-
Authorization: `Bearer ${token}`,
56+
await axios.get(
57+
`${process.env.REACT_APP_API_ENDPOINT}/submissions/${processId}`,
58+
{
59+
headers: {
60+
Authorization: `Bearer ${token}`,
61+
},
5662
},
57-
});
63+
);
5864
return res.data;
5965
},
6066
{

src/api/users.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ function useProfile() {
66
const { token } = useToken();
77

88
return useQuery<{ email: string }, Error>('profile', async () => {
9-
const { data } = await axios.get('http://localhost:3000/users/stan', {
10-
headers: {
11-
Authorization: `Bearer ${token}`,
9+
const { data } = await axios.get(
10+
`${process.env.REACT_APP_API_ENDPOINT}/users/stan`,
11+
{
12+
headers: {
13+
Authorization: `Bearer ${token}`,
14+
},
1215
},
13-
});
16+
);
1417
return data;
1518
});
1619
}

0 commit comments

Comments
 (0)