Skip to content

Commit

Permalink
added environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanehab98 committed Jan 2, 2023
1 parent f47b3d0 commit c85fd05
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .env.all
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REACT_APP_BASE_URL = "https://scandiweb-task-marwan-elsheikh.000webhostapp.com/"
REACT_APP_ADD_URL = "https://scandiweb-task-marwan-elsheikh.000webhostapp.com/addproduct/"
REACT_APP_DELETE_URL = "https://scandiweb-task-marwan-elsheikh.000webhostapp.com/deleteproduct/"
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.5.0",
"axios": "^1.2.1",
"bootstrap": "^5.3.0-alpha1",
"env-cmd": "^10.1.0",
"react": "^18.2.0",
"react-bootstrap": "^2.7.0",
"react-dom": "^18.2.0",
Expand All @@ -16,8 +17,8 @@
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"start": "env-cmd -f .env.all react-scripts start",
"build": "env-cmd -f .env.all react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build"
Expand Down
6 changes: 4 additions & 2 deletions server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
$class = $type;
$product_object = new $class($product, true);
$product_object->addProduct($conn, $type);
} else {
} else if ($path[1] == "deleteproduct") {
$body = json_decode(file_get_contents('php://input'));
$sku = $body->SKU;
$products_list = new ProductList();
$products_list->deleteProduct($conn, $path[2]);
$products_list->deleteProduct($conn, $sku);
}
break;
}
2 changes: 1 addition & 1 deletion src/components/CreateProduct/CreateProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function CreateProduct() {
if (valid) {
try {
// console.log(product)
fetch('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/addproduct', {
fetch(process.env.REACT_APP_ADD_URL, {
method: 'post',
body: JSON.stringify(product)
}).then(function (response) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ProductsList/ProductsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function ProductsList() {

function getProducts() {
try {
fetch('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/', {
fetch(process.env.REACT_APP_BASE_URL, {
method: 'get',
}).then(function (response) {
return response.json();
Expand All @@ -46,8 +46,9 @@ export default function ProductsList() {
let tempSelected = [];
Object.assign(tempSelected, selected);
try {
fetch('https://scandiweb-task-marwan-elsheikh.000webhostapp.com/deleteproduct/' + SKU, {
fetch(process.env.REACT_APP_DELETE_URL, {
method: 'post',
body: JSON.stringify({"SKU": SKU})
}).then(function (response) {
return response.json();
}).then(function (data) {
Expand Down

0 comments on commit c85fd05

Please sign in to comment.