Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEBUGGED SERVER PROXY FAILURE #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "client",
"version": "0.1.0",
"proxy": "http://localhost:5000",
"private": true,
"dependencies": {
"axios": "^0.18.0",
Expand All @@ -18,6 +19,5 @@
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000"
}
}
55 changes: 32 additions & 23 deletions client/src/components/Product/Product.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import React from 'react';
import "./Product.css";
import './Product.css';
import PropTypes from 'prop-types';

const Product = props => {
return (
<div className="Product-Wrapper">
<div className="Product">
<div className="Product-Image-Wrapper">
<img src={props.photo} alt={props.name} className="Product-Image" />
</div>
<div className="Product-Title">
<p className="Product-Name">{props.name}</p>
</div>
<div className="Product-Data">
<small className="Product-Price">${props.price}</small>
<button onClick={ props.addToCart } className="product-button Product-Add">Add to Cart</button>
</div>
</div>
</div>
);
const Product = (props) => {
return (
<div className='Product-Wrapper'>
<div className='Product'>
<div className='Product-Image-Wrapper'>
<img
src={props.photo}
alt={props.name}
className='Product-Image'
/>
</div>
<div className='Product-Title'>
<p className='Product-Name'>{props.name}</p>
</div>
<div className='Product-Data'>
<small className='Product-Price'>${props.price}</small>
<button
onClick={props.addToCart}
className='product-button Product-Add'
>
Add to Cart
</button>
</div>
</div>
</div>
);
};

Product.propTypes = {
name: PropTypes.string.isRequired,
photo: PropTypes.string.isRequired,
price: PropTypes.number.isRequired,
addToCart: PropTypes.func.isRequired
name: PropTypes.string.isRequired,
// photo: PropTypes.string.isRequired,
price: PropTypes.number.isRequired,
addToCart: PropTypes.func.isRequired,
};

export default Product;
export default Product;
22 changes: 11 additions & 11 deletions client/src/store/actions/products.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import axios from 'axios';
import { FETCH_PRODUCTS } from './types';

export const fetchProducts = () => async dispatch => {
try {
const res = await axios("/api/products/")
dispatch({
type: FETCH_PRODUCTS,
payload: res.data.products
})
} catch (err) {
console.log(err.message);
}
};
export const fetchProducts = () => async (dispatch) => {
try {
const res = await axios('/api/products/');
dispatch({
type: FETCH_PRODUCTS,
payload: res.data.products,
});
} catch (err) {
console.log(err.message);
}
};
4 changes: 2 additions & 2 deletions config/keys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
MONGO_URL: process.env.MONGO_URL
};
MONGO_URL: process.env.MONGO_URL,
};
7 changes: 4 additions & 3 deletions routes/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const router = express.Router();
const Products = require('../models/Product');

router.get('/', async (req, res) => {
const products = await Products.find({});
res.json({ products });
const products = await Products.find({});
console.log('WORKING ROUTE');
res.json({ products });
});

module.exports = router;
module.exports = router;
18 changes: 9 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ const PORT = process.env.PORT || 5000;
app.use(require('helmet')());
app.use(require('cors')());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Routes
app.use('/api/products', require('./routes/products'));
// app.use(bodyParser.json());
// Routes
app.use('/api/products', require('./routes/products'));

// Production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
// Set static folder
app.use(express.static('client/build'));

app.get('*', (req, res) => {
res.sendfile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
app.get('*', (req, res) => {
res.sendfile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}

app.listen(PORT, () => console.log(`Server running on port ${ PORT }`));
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));