Skip to content

Commit 3409262

Browse files
committed
Refactor export and import handlers to use BACKEND_URL for API requests
1 parent c0a5984 commit 3409262

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export const BACKEND_URL = import.meta.env.VITE_BACKEND_URL;
12
export const BASE_URL = import.meta.env.VITE_BASE_URL;

src/controllers/exportHandler.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
import Axios from "axios";
2-
import { BASE_URL } from "../constants";
2+
import { BACKEND_URL, BASE_URL } from "../constants";
33

4-
const URL = `${BASE_URL}/share/export`;
4+
const URL = `${BACKEND_URL}/share/export`;
55

66
const exportHandler = (code, language, input, expire, setIsLoading, setId) => {
7-
// console.log({
8-
// code: code,
9-
// language: language,
10-
// input: input,
11-
// expire: expire,
12-
// setIsLoading: setIsLoading,
13-
// setId,
14-
// setId,
15-
// });
16-
Axios.post(URL, {
17-
code: code,
18-
language: language,
19-
input: input,
20-
expireIndex: expire.value,
7+
// console.log({
8+
// code: code,
9+
// language: language,
10+
// input: input,
11+
// expire: expire,
12+
// setIsLoading: setIsLoading,
13+
// setId,
14+
// setId,
15+
// });
16+
Axios.post(URL, {
17+
code: code,
18+
language: language,
19+
input: input,
20+
expireIndex: expire.value,
21+
})
22+
.then((response) => {
23+
console.log(response);
24+
setIsLoading(false);
25+
if (response.data.success) {
26+
// console.log(response["data"]["id"]);
27+
setId(`${BASE_URL}/#/${response["data"]["id"]}`);
28+
}
2129
})
22-
.then((response) => {
23-
console.log(response);
24-
setIsLoading(false);
25-
if (response.data.success) {
26-
// console.log(response["data"]["id"]);
27-
setId(response["data"]["id"]);
28-
}
29-
})
30-
.catch((error) => {
31-
console.log(error);
32-
setIsLoading(false);
33-
setId("Cannot Share your code");
34-
});
30+
.catch((error) => {
31+
console.log(error);
32+
setIsLoading(false);
33+
setId("Cannot Share your code");
34+
});
3535
};
3636

3737
export default exportHandler;

src/controllers/importHandler.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Axios from "axios";
2-
import { BASE_URL } from "../constants";
2+
import { BACKEND_URL } from "../constants";
33

4-
const URL = `${BASE_URL}/share/import`;
4+
const URL = `${BACKEND_URL}/share/import`;
55

66
const importHandler = async (
77
id,

0 commit comments

Comments
 (0)