[Bug]: Hardcoded IP causing Testing to fail #2
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
When deploying to multiple environments to test, the backend database does not respond properly within the app. The IP address is hard coded and needs to be updated to accept .env variables
Steps to Reproduce
Depploy to new environment
Run ./start-servers.sh
Refresh page
"Failed to fetch CVE's" and other API call failures:
Environment
Microsoft Edge/ Windows 11
Relevant Log Output
No response
Files to Create
backend/.env
PORT=3001
CORS_ORIGINS=http://YOUR_IP:3000
frontend/.env
REACT_APP_API_BASE=http://YOUR_IP:3001/api
REACT_APP_API_HOST=http://YOUR_IP:3001
Code Changes
backend/server.js - add at top:
require('dotenv').config();
Replace hardcoded PORT and CORS with process.env values.
frontend/src/App.js - replace hardcoded API_BASE:
const API_BASE = process.env.REACT_APP_API_BASE || 'http://localhost:3001/api';
Critical: Restart Required
React caches env vars at startup. After changes:
pkill -f "react-scripts" && pkill -f node
./start-servers.sh
Page refresh alone will NOT work.