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

Revert stuff #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const axios = require('axios');
const fs = require('fs');
const csv = require('csv-parser');
const app = express();
const port = 3000;
const port = process.env.PORT || 3000;

const cookieParser = require('cookie-parser');
const jwt = require('jsonwebtoken');
Expand All @@ -25,7 +25,7 @@ app.use(morgan("dev")) // morgan has a few logging default styles - dev is a nic
app.use(express.json()) // decode JSON-formatted incoming POST data
app.use(express.urlencoded({ extended: true })) // decode url-encoded incoming POST data
app.use(cookieParser());
app.use(cors({ origin: "http://localhost:3001", credentials: true }));
app.use(cors({ origin: `${process.env.FRONTEND_URL}`, credentials: true }));

//connect to mongodb server
try {
Expand Down
2 changes: 1 addition & 1 deletion back-end/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const http = require('http');
const express = require('express');
const app = express();
const port = 3000;
const port = process.env.PORT || 3000;


const server = http.createServer(app);
Expand Down
2 changes: 1 addition & 1 deletion front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "set PORT=3001 && react-scripts start",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function App() {

useEffect(() => {
const fetchData = async () => {
const response = await fetch('http://localhost:3000/api/allproducts');
const response = await fetch(`${process.env.REACT_APP_API_URL}/api/allproducts`);
const data = await response.json();
setProducts(data);
};
Expand All @@ -37,7 +37,7 @@ function App() {

const fetchCurrentUser = async () => {
try {
const response = await fetch('http://localhost:3000/api/current-user', {
const response = await fetch(`${process.env.REACT_APP_API_URL}/api/current-user`, {
credentials: 'include',
});
const data = await response.json();
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Messages = () => {
useEffect(() => {
const fetchConversations = async () => {
try {
const response = await fetch(`http://localhost:3000/api/conversations/`, {credentials: 'include',});
const response = await fetch(`${process.env.REACT_APP_API_URL}/api/conversations/`, {credentials: 'include',});
const { conversations, userId } = await response.json(); // extract userId from JSON response
setConversations(conversations);
setUserId(userId); // store userId in state variable
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/MyListings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MyListings = () =>{
useEffect(() => {
const fetchListings = async () => {
try {
const response = await axios.get('http://localhost:3000/api/mylistings');
const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/mylistings`);
setListings(response.data);
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/MyOffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MyOffers = () =>{
useEffect(() => {
const fetchOffers = async () => {
try {
const response = await axios.get('http://localhost:3000/api/myoffers');
const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/myoffers`);
setOffers(response.data);
} catch (error) {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/MyProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MyProfile = () => {
const handleClick = async () => {

try {
axios.get('http://localhost:3000/logout')
axios.get(`${process.env.REACT_APP_API_URL}/api/logout`)
.then(response => {
navigate('/signin');
})
Expand All @@ -27,7 +27,7 @@ const MyProfile = () => {
useEffect(() => {
const fetchuserinfo = async () => {
try {
const response = await axios.get('http://localhost:3000/api/myprofile');
const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/myprofile`);
setName(response.data.name);
setImageUrl(response.data.imageUrl);
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions front-end/src/NewProductListing.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const NewProductListing = () => {
useEffect(() => {
// Fetch data for the listing with the given ID from the server
// Replace this with your actual API call
axios.get(`http://localhost:3000/api/products/${id}`)
axios.get(`${process.env.REACT_APP_API_URL}/api/products/${id}`)
.then((res) => {
setData(res.data);
//console.log(data);
Expand Down Expand Up @@ -68,7 +68,7 @@ const NewProductListing = () => {
const listingImage = data.images;
const payload = {seller, offerPrice, listedPrice, id, listingName, listingImage };
try{
const response = await axios.post('http://localhost:3000/api/create-offers', payload)
const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/create-offers`, payload)
}
catch(err) {
console.log(err);
Expand Down Expand Up @@ -100,7 +100,7 @@ const NewProductListing = () => {
console.log(data)

try {
const response = await axios.post('http://localhost:3000/api/new_conversation', {
const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/new_conversation`, {
userId: data.user.id, // replace with the actual ID of the seller
});
console.log(response)
Expand All @@ -123,7 +123,7 @@ const NewProductListing = () => {
return `${month}/${day}/${year}`;
}

const publicUrl = process.env.REACT_APP_UPLOADS_URL || 'http://localhost:3000/uploads/'; //folder in backend with multer image uploads
const publicUrl = process.env.REACT_APP_UPLOADS_URL || `${process.env.REACT_APP_API_URL}/uploads/`; //folder in backend with multer image uploads

return (
<Grid container justifyContent="center">
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/PurchaseHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function PurchaseHistory() {
useEffect(() => {
const fetchPurchases = async () => {
try {
const response = await axios.get('http://localhost:3000/api/mypurchases');
const response = await axios.get(`${process.env.REACT_APP_API_URL}/api/mypurchases`);
setPurchases(response.data);
} catch (error) {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/Sell.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Sell = ({ onNewListing }) => {
for(let i = 0; i < images.length; i++){
formData.append('images', images[i]);
}
axios.post('http://localhost:3000/api/sell', formData)
axios.post(`${process.env.REACT_APP_API_URL}/api/sell`, formData)
.then((res)=>{
setOpenSnackbar(true);
setTitle('');
Expand All @@ -104,7 +104,7 @@ const Sell = ({ onNewListing }) => {

//just a demonstration, accounts will be setup in database
const submitListings = () => {
axios.post('http://localhost:3000/api/myoffers', {
axios.post(`${process.env.REACT_APP_API_URL}/api/myoffers`, {
offerPrice: Math.floor(Math.random() * 100) + 1,
listedPrice: price,
date: date,
Expand Down
4 changes: 2 additions & 2 deletions front-end/src/Signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Signin = () => {
useEffect(() => {
const checkAuth = async () => {
try {
const response = await axios.get('http://localhost:3000/authenticate');
const response = await axios.get(`${process.env.REACT_APP_API_URL}/authenticate`);
if (response.status === 200) {
navigate('/home');
}
Expand All @@ -53,7 +53,7 @@ const Signin = () => {

try {
const payload = { username, password };
const response = await axios.post('http://localhost:3000/signin', payload);
const response = await axios.post(`${process.env.REACT_APP_API_URL}/signin`, payload);
if (response.data && response.data.success) {
alert("Logged in successfully!");
navigate('/home');
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SignUp = () => {

try {
const payload = {username, password};
axios.post('http://localhost:3000/signup', payload)
axios.post(`${process.env.REACT_APP_API_URL}/signup`, payload)
.then(response => {
alert("Account created Successfully!");
navigate('/signin');
Expand Down
5 changes: 3 additions & 2 deletions front-end/src/chat/chatwindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function ChatWindow({ currentUserId }) {
async function fetchMessages() {
try {
console.log(token)
const response = await fetch(`http://localhost:3000/api/messages/${conversationId}`, {

const response = await fetch(`${process.env.REACT_APP_API_URL}/api/messages/${conversationId}`, {
headers: {
userId: currentUserId// Include the JWT token in the headers
},
Expand Down Expand Up @@ -44,7 +45,7 @@ function ChatWindow({ currentUserId }) {
console.log('Conversation ID in ChatWindow:', conversationId);
console.log('Submitting message:', message);
try {
const response = await fetch(`http://localhost:3000/api/messages/${conversationId}`, {
const response = await fetch(`${process.env.REACT_APP_API_URL}/api/messages/${conversationId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/components/ListingsIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ListingsIcon = ({ productName, listedPrice, listingId, date, imageUrl, id,
const confirmDelete = window.confirm('Are you sure you want to delete this listing?');
if(confirmDelete) {
try{
const response = await axios.delete(`http://localhost:3000/api/delete/${listingId}`)
const response = await axios.delete(`${process.env.REACT_APP_API_URL}/api/delete/${listingId}`)
if(response.status === 200) {
console.log('Deleted Listing ')
onDelete(listingId)
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/components/OffersIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const OffersIcon = ({productName, listedPrice, offerPrice, date, imageUrl, id, o
const confirmDelete = window.confirm('Are you sure you want to decline this offer?');
if(confirmDelete) {
try{
const response = await axios.post('http://localhost:3000/api/delete-offers', {id})
const response = await axios.post(`${process.env.REACT_APP_API_URL}/api/delete-offers`, {id})
if(response.status === 200) {
console.log('Deleted Listing ')
onDelete(id);
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/components/Protected.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ProtectedRoute = ({ children }) => {
useEffect(() => {
const checkAuth = async () => {
try {
const response = await axios.get('http://localhost:3000/authenticate');
const response = await axios.get(`${process.env.REACT_APP_API_URL}/authenticate`);
if (response.status === 200) {
setAuthenticated(true);
setLoading(false);
Expand Down