diff --git a/safeshare/safeshare-frontend/env b/safeshare/safeshare-frontend/env new file mode 100644 index 0000000..df7073a --- /dev/null +++ b/safeshare/safeshare-frontend/env @@ -0,0 +1,2 @@ +REACT_APP_API_HOST=http://127.0.0.1 +REACT_APP_API_PORT=8000 diff --git a/safeshare/safeshare-frontend/src/pages/downloadFile.js b/safeshare/safeshare-frontend/src/pages/downloadFile.js index 5494738..6f6731c 100644 --- a/safeshare/safeshare-frontend/src/pages/downloadFile.js +++ b/safeshare/safeshare-frontend/src/pages/downloadFile.js @@ -20,6 +20,10 @@ function DownloadFile() { const [errorMsg, setErrorcode] = useState(''); let subtitle; const [modalIsOpen, setIsOpen] = React.useState(false); + const apiHost = process.env.REACT_APP_API_HOST || 'localhost'; + const apiPort = process.env.REACT_APP_API_PORT || '8000'; + + const apiUrl = `${apiHost}:${apiPort}`; function openModal() { setIsOpen(true); @@ -40,7 +44,7 @@ function DownloadFile() { const handleDownloadFile = () => { if (passcode) { - axios.get(`http://127.0.0.1:8000/api/files/${passcode}/`, {responseType: 'blob'}) + axios.get(`${apiUrl}/api/files/${passcode}/`, {responseType: 'blob'}) .then(response => { let filename = 'downloaded_file'; // Default filename let mimeType = 'application/octet-stream'; // Default MIME type diff --git a/safeshare/safeshare-frontend/src/pages/shareFile.js b/safeshare/safeshare-frontend/src/pages/shareFile.js index b9e8175..7085ffb 100644 --- a/safeshare/safeshare-frontend/src/pages/shareFile.js +++ b/safeshare/safeshare-frontend/src/pages/shareFile.js @@ -23,7 +23,10 @@ function ShareFile() { const [errorMsg, setErrorcode] = useState(''); let subtitle; const [modalIsOpen, setIsOpen] = React.useState(false); + const apiHost = process.env.REACT_APP_API_HOST || 'localhost'; + const apiPort = process.env.REACT_APP_API_PORT || '8000'; + const apiUrl = `${apiHost}:${apiPort}`; function openModal() { setIsOpen(true); @@ -42,6 +45,7 @@ function ShareFile() { setFile(file); //setPasscode('1234'); console.log(file); + console.log(apiUrl); if (file) { const formData = new FormData(); formData.append('file', file); @@ -49,7 +53,7 @@ function ShareFile() { // Send POST request to the backend API using Axios axios - .post('http://127.0.0.1:8000/api/files/', formData) + .post(`${apiUrl}/api/files/`, formData) .then((response) => { // Handle a successful response from the server, set passcode to "key" in the response body const data = response.data; @@ -57,7 +61,7 @@ function ShareFile() { // If data is an array, take the first item if (Array.isArray(data)) { const passcode = data[0].key; - const baseUrl = 'http://localhost:8000/api/files/'; + const baseUrl = '${apiUrl}/api/files/'; setPasscode(passcode); setShareableLink(baseUrl + passcode);