Skip to content

Commit d16ea90

Browse files
committed
Updated: call baseurL with appConfig
1 parent 53a3635 commit d16ea90

File tree

9 files changed

+54
-51
lines changed

9 files changed

+54
-51
lines changed

backend/config/cors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
'allowed_methods' => ['*'],
2121

22-
'allowed_origins' => [env('FRONTEND_URL', 'http://localhost:3000'), 'http://localhost:5173'],
22+
'allowed_origins' => [env('FRONTEND_URL', 'http://localhost:3000'), 'http://localhost:5173', 'http://192.168.18.11:5173'],
2323

2424
'allowed_origins_patterns' => [],
2525

frontend/src/config/appConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const appConfig = {
22
debounceTimeout: 750,
3+
expirationTime: 60 * 60 * 1000,
4+
baseURL: "http://127.0.0.1:8000/",
5+
baseurlAPI: "http://127.0.0.1:8000/api",
36
};
47

58
export default appConfig;

frontend/src/pages/Auth/Login.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import Swal from "sweetalert2";
33
import React, { useEffect, useState } from "react";
44
import { Link, useNavigate } from "react-router-dom";
55
import withReactContent from "sweetalert2-react-content";
6-
6+
import appConfig from "../../config/appConfig";
77
import { setTokenWithExpiration, getTokenWithExpiration } from "./Session";
88

99
export default function Login() {
10-
const baseURL = "http://127.0.0.1:8000/api";
11-
1210
const navigate = useNavigate();
1311
const MySwal = withReactContent(Swal);
1412

@@ -65,7 +63,7 @@ export default function Login() {
6563

6664
if (validateForm()) {
6765
axios
68-
.post(`${baseURL}/login`, formData, {
66+
.post(`${appConfig.baseurlAPI}/login`, formData, {
6967
headers: {
7068
"Content-Type": "application/json",
7169
},

frontend/src/pages/Auth/Register.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import axios from "axios";
22
import Swal from "sweetalert2";
33
import React, { useEffect, useState } from "react";
44
import { Link, useNavigate } from "react-router-dom";
5+
import appConfig from "../../config/appConfig";
56
import withReactContent from "sweetalert2-react-content";
67

78
export default function Register() {
8-
const baseURL = "http://127.0.0.1:8000/api";
9-
109
const navigate = useNavigate();
1110
const MySwal = withReactContent(Swal);
1211

@@ -86,7 +85,7 @@ export default function Register() {
8685

8786
if (validateForm()) {
8887
axios
89-
.post(`${baseURL}/register`, formData, {
88+
.post(`${appConfig.baseurlAPI}/register`, formData, {
9089
headers: {
9190
"Content-Type": "application/json",
9291
},

frontend/src/pages/Auth/Session.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import appConfig from "../../config/appConfig";
2+
13
export function setTokenWithExpiration(key, token) {
24
const now = new Date();
3-
const expirationTime = now.getTime() + 60 * 60 * 1000;
5+
const expirationTime = now.getTime() + appConfig.expirationTime;
46
const item = token + "|" + expirationTime;
57
localStorage.setItem(key, item);
68
}

frontend/src/pages/Gallery/Gallery.jsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { useNavigate } from "react-router-dom";
99
import appConfig from "../../config/appConfig";
1010

1111
export default function Gallery() {
12-
const baseURL = "http://127.0.0.1:8000/";
13-
const baseurlAPI = "http://127.0.0.1:8000/api";
14-
1512
const navigate = useNavigate();
1613

1714
const [rows, setProducts] = useState([]);
@@ -32,7 +29,7 @@ export default function Gallery() {
3229
document.title = "Gallery";
3330
axios
3431
.get(
35-
`${baseurlAPI}/gallery?page=${currentPage}&per_page=${showing}&search=${searchTerm}&showing=${showing}`
32+
`${appConfig.baseurlAPI}/gallery?page=${currentPage}&per_page=${showing}&search=${searchTerm}&showing=${showing}`
3633
)
3734
.then((data) => {
3835
setProducts(data.data.data.data);
@@ -150,7 +147,7 @@ export default function Gallery() {
150147
if (!isEditing) {
151148
if (validateForm()) {
152149
axios
153-
.post(`${baseurlAPI}/gallery`, formData, {
150+
.post(`${appConfig.baseurlAPI}/gallery`, formData, {
154151
headers: {
155152
"Content-Type": "multipart/form-data",
156153
},
@@ -192,11 +189,15 @@ export default function Gallery() {
192189
data.append("image", formData.image);
193190
data.append("_method", "put");
194191
axios
195-
.post(`${baseurlAPI}/gallery/${modalData.id}`, data, {
196-
headers: {
197-
"Content-Type": "multipart/form-data",
198-
},
199-
})
192+
.post(
193+
`${appConfig.baseurlAPI}/gallery/${modalData.id}`,
194+
data,
195+
{
196+
headers: {
197+
"Content-Type": "multipart/form-data",
198+
},
199+
}
200+
)
200201
.then((response) => {
201202
if (response.status === 200) {
202203
Swal.fire({
@@ -248,7 +249,7 @@ export default function Gallery() {
248249

249250
const handleDelete = (id) => {
250251
axios
251-
.delete(`${baseurlAPI}/gallery/${id}`)
252+
.delete(`${appConfig.baseurlAPI}/gallery/${id}`)
252253
.then((data) => {
253254
console.log("Success:", data);
254255
setProducts(rows.filter((row) => row.id !== id));
@@ -344,7 +345,7 @@ export default function Gallery() {
344345
<td>
345346
<a
346347
href={
347-
baseURL +
348+
appConfig.baseURL +
348349
"storage/images/" +
349350
row.image
350351
}
@@ -353,7 +354,7 @@ export default function Gallery() {
353354
<img
354355
className="tw-aspect-square tw-w-4/6 tw-rounded-lg"
355356
src={
356-
baseURL +
357+
appConfig.baseURL +
357358
"storage/images/" +
358359
row.image
359360
}

frontend/src/pages/MultipleInsert/MultipleInsert.jsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { useNavigate } from "react-router-dom";
99
import appConfig from "../../config/appConfig";
1010

1111
export default function MultipleInsert() {
12-
const baseURL = "http://127.0.0.1:8000/";
13-
const baseurlAPI = "http://127.0.0.1:8000/api";
14-
1512
const MySwal = withReactContent(Swal);
1613
const navigate = useNavigate();
1714

@@ -32,7 +29,7 @@ export default function MultipleInsert() {
3229
document.title = "Products";
3330
axios
3431
.get(
35-
`${baseurlAPI}/products?page=${currentPage}&per_page=${showing}&search=${searchTerm}&showing=${showing}`
32+
`${appConfig.baseurlAPI}/products?page=${currentPage}&per_page=${showing}&search=${searchTerm}&showing=${showing}`
3633
)
3734
.then((data) => {
3835
setRows(data.data.data.data);
@@ -157,7 +154,7 @@ export default function MultipleInsert() {
157154
if (!isEditing) {
158155
if (validateForm()) {
159156
axios
160-
.post(`${baseurlAPI}/products`, formData, {
157+
.post(`${appConfig.baseurlAPI}/products`, formData, {
161158
headers: {
162159
"Content-Type": "application/json",
163160
},
@@ -191,11 +188,15 @@ export default function MultipleInsert() {
191188
} else {
192189
if (validateForm()) {
193190
axios
194-
.put(`${baseurlAPI}/products/${modalData.id}`, formData, {
195-
headers: {
196-
"Content-Type": "application/json",
197-
},
198-
})
191+
.put(
192+
`${appConfig.baseurlAPI}/products/${modalData.id}`,
193+
formData,
194+
{
195+
headers: {
196+
"Content-Type": "application/json",
197+
},
198+
}
199+
)
199200
.then((response) => {
200201
if (response.status === 200) {
201202
Swal.fire({
@@ -243,7 +244,7 @@ export default function MultipleInsert() {
243244

244245
const handleDelete = (id) => {
245246
axios
246-
.delete(`${baseurlAPI}/products/${id}`)
247+
.delete(`${appConfig.baseurlAPI}/products/${id}`)
247248
.then((data) => {
248249
console.log("Success:", data);
249250
setRows(rows.filter((row) => row.id !== id));
@@ -298,7 +299,7 @@ export default function MultipleInsert() {
298299

299300
axios
300301
.post(
301-
`${baseurlAPI}/products/multiple-store`,
302+
`${appConfig.baseurlAPI}/products/multiple-store`,
302303
{ inputs: inputs },
303304
{
304305
headers: {

frontend/src/pages/Profile/Profile.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import Case from "../../components/Case";
33
import Swal from "sweetalert2";
44
import withReactContent from "sweetalert2-react-content";
55
import axios from "axios";
6+
import appConfig from "../../config/appConfig";
67

78
export default function Profile() {
8-
const baseURL = "http://127.0.0.1:8000/";
9-
const baseurlAPI = "http://127.0.0.1:8000/api";
10-
119
const [user, setUser] = useState([]);
1210
const [isLoading, setIsLoading] = useState(true);
1311
const [refetch, setRefetch] = useState(Math.random());
@@ -18,7 +16,7 @@ export default function Profile() {
1816
document.title = "My Profile";
1917

2018
axios
21-
.get(`${baseurlAPI}/profile`)
19+
.get(`${appConfig.baseurlAPI}/profile`)
2220
.then((data) => {
2321
setUser(data.data.data);
2422
setFormProfile({
@@ -150,7 +148,7 @@ export default function Profile() {
150148

151149
if (validateFormProfile()) {
152150
axios
153-
.put(`${baseurlAPI}/profile`, formProfile, {
151+
.put(`${appConfig.baseurlAPI}/profile`, formProfile, {
154152
headers: {
155153
"Content-Type": "application/json",
156154
},
@@ -186,7 +184,7 @@ export default function Profile() {
186184

187185
if (validateFormPassword()) {
188186
axios
189-
.put(`${baseurlAPI}/update-password`, formPassword, {
187+
.put(`${appConfig.baseurlAPI}/update-password`, formPassword, {
190188
headers: {
191189
"Content-Type": "application/json",
192190
},

frontend/src/pages/products/Product.jsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { useNavigate } from "react-router-dom";
99
import appConfig from "../../config/appConfig";
1010

1111
export default function Product() {
12-
const baseURL = "http://127.0.0.1:8000/";
13-
const baseurlAPI = "http://127.0.0.1:8000/api";
14-
1512
const navigate = useNavigate();
1613

1714
const [rows, setRows] = useState([]);
@@ -32,7 +29,7 @@ export default function Product() {
3229
document.title = "Products";
3330
axios
3431
.get(
35-
`${baseurlAPI}/products?page=${currentPage}&per_page=${showing}&search=${searchTerm}&showing=${showing}`
32+
`${appConfig.baseurlAPI}/products?page=${currentPage}&per_page=${showing}&search=${searchTerm}&showing=${showing}`
3633
)
3734
.then((data) => {
3835
setRows(data.data.data.data);
@@ -161,7 +158,7 @@ export default function Product() {
161158
if (!isEditing) {
162159
if (validateForm()) {
163160
axios
164-
.post(`${baseurlAPI}/products`, formData, {
161+
.post(`${appConfig.baseurlAPI}/products`, formData, {
165162
headers: {
166163
"Content-Type": "application/json",
167164
},
@@ -195,11 +192,15 @@ export default function Product() {
195192
} else {
196193
if (validateForm()) {
197194
axios
198-
.put(`${baseurlAPI}/products/${modalData.id}`, formData, {
199-
headers: {
200-
"Content-Type": "application/json",
201-
},
202-
})
195+
.put(
196+
`${appConfig.baseurlAPI}/products/${modalData.id}`,
197+
formData,
198+
{
199+
headers: {
200+
"Content-Type": "application/json",
201+
},
202+
}
203+
)
203204
.then((response) => {
204205
if (response.status === 200) {
205206
Swal.fire({
@@ -251,7 +252,7 @@ export default function Product() {
251252

252253
const handleDelete = (id) => {
253254
axios
254-
.delete(`${baseurlAPI}/products/${id}`)
255+
.delete(`${appConfig.baseurlAPI}/products/${id}`)
255256
.then((data) => {
256257
console.log("Success:", data);
257258
setRows(rows.filter((row) => row.id !== id));

0 commit comments

Comments
 (0)