This document explains how to set up and use the local proxy server to bypass CORS issues with the News API.
-
Install proxy server dependencies:
npm run proxy:install
-
Start only the proxy server:
npm run docker:proxy
-
Or start both proxy and React app:
npm run docker:dev
-
Install proxy dependencies:
npm run proxy:install
-
Start proxy and React app concurrently:
npm run dev:with-proxy
-
Or run them separately:
# Terminal 1 npm run proxy:dev # Terminal 2 npm start
Create a .env file in the project root:
SASS_PATH=./node_modules;./src
HTTPS=true
PORT=8443
REACT_APP_API_KEY=your_newsapi_key_here
REACT_APP_PROXY_URL=http://localhost:3001The docker-compose.yml includes:
- proxy-server: Runs on port 3001
- web: React app on port 8443 (optional, use profile
full-stack)
- Health Check:
GET /health - News API Proxy:
GET /api/news/*
npm run proxy:install- Install proxy server dependenciesnpm run proxy:dev- Start proxy in development mode with nodemonnpm run proxy:start- Start proxy in production modenpm run docker:proxy- Start only proxy server with Dockernpm run docker:dev- Start full stack with Dockernpm run docker:build- Build Docker imagesnpm run dev:with-proxy- Start both proxy and React app locally
- The proxy server receives requests at
/api/news/* - It forwards them to
https://newsapi.org/v2/* - It adds proper CORS headers for local development
- The React app makes requests to the local proxy instead of directly to News API
- ✅ No reliance on external CORS proxy services
- ✅ Better control over request/response handling
- ✅ Local development environment isolation
- ✅ Docker support for consistent deployment
- ✅ Health checks and error handling