A web application that displays news articles from different perspectives (liberal, conservative, and neutral).
news-perspectives-app/
├── backend/
│ ├── models/
│ │ └── Article.js
│ ├── routes/
│ │ └── news.js
│ ├── services/
│ │ └── summaryService.js
│ ├── .env
│ ├── package.json
│ └── server.js
└── frontend/
├── public/
├── src/
│ ├── components/
│ │ ├── ArticleList.js
│ │ ├── NavBar.js
│ │ ├── PerspectiveToggle.js
│ │ └── SummaryView.js
│ ├── App.css
│ ├── App.js
│ └── index.js
└── package.json
- Node.js (v14 or higher)
- Supabase account and project
- OpenAI API key
- NewsAPI key
- Docker (for containerization)
- Google Cloud account (for Cloud Run deployment)
-
Navigate to the backend directory:
cd backend -
Install dependencies:
npm install -
Create a
.envfile with the following variables (see.env.examplefor a template):# OpenAI API Key - Get from https://platform.openai.com/api-keys OPENAI_API_KEY=your_openai_api_key_here # NewsAPI Key - Get from https://newsapi.org/register NEWS_API_KEY=your_newsapi_key_here # Supabase Configuration SUPABASE_URL=https://ueqselkevtzpzgcapbzc.supabase.co SUPABASE_KEY=your_supabase_key_here # Server Configuration PORT=5001 -
Start the development server:
npm run dev -
Manually refresh articles (optional):
npm run refresh-articles
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install -
Start the development server:
npm start
You can run the entire application using Docker Compose:
docker-compose up
This will start both the frontend and backend services.
The application includes an automatic article refresh mechanism to ensure that headlines don't remain at the top all day:
-
Scheduled Refresh: The backend server automatically refreshes articles every 3 hours using a cron job.
-
Article Rotation: Articles are rotated based on a weighted algorithm that considers:
- Article age (newer articles are prioritized)
- Time since last shown (articles not shown recently get higher priority)
- Time-of-day variation (creates a subtle shift in article selection every hour)
-
Manual Refresh: Users can manually refresh articles by clicking the "Refresh Stories" button.
-
Standalone Script: A standalone script is available for manual or scheduled refreshes:
npm run refresh-articles
-
Build and push the backend image:
cd backend gcloud builds submit --tag gcr.io/[PROJECT_ID]/news-perspectives-backend gcloud run deploy news-perspectives-backend --image gcr.io/[PROJECT_ID]/news-perspectives-backend --platform managed --region us-central1 --allow-unauthenticated --set-env-vars OPENAI_API_KEY=[YOUR_OPENAI_API_KEY],NEWS_API_KEY=[YOUR_NEWS_API_KEY],SUPABASE_URL=[YOUR_SUPABASE_URL],SUPABASE_KEY=[YOUR_SUPABASE_KEY] -
Build and push the frontend image:
cd frontend gcloud builds submit --tag gcr.io/[PROJECT_ID]/news-perspectives-frontend gcloud run deploy news-perspectives-frontend --image gcr.io/[PROJECT_ID]/news-perspectives-frontend --platform managed --region us-central1 --allow-unauthenticated
-
Set up secret environment variables in Secret Manager:
gcloud secrets create OPENAI_API_KEY --replication-policy automatic gcloud secrets create NEWS_API_KEY --replication-policy automatic gcloud secrets create SUPABASE_URL --replication-policy automatic gcloud secrets create SUPABASE_KEY --replication-policy automatic echo -n "your_openai_api_key" | gcloud secrets versions add OPENAI_API_KEY --data-file=- echo -n "your_news_api_key" | gcloud secrets versions add NEWS_API_KEY --data-file=- echo -n "your_supabase_url" | gcloud secrets versions add SUPABASE_URL --data-file=- echo -n "your_supabase_key" | gcloud secrets versions add SUPABASE_KEY --data-file=- -
Grant Secret Manager access to Cloud Build service account:
gcloud projects add-iam-policy-binding [PROJECT_ID] \ --member="serviceAccount:[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com" \ --role="roles/secretmanager.secretAccessor" -
Set up a Cloud Build trigger connected to your GitHub repository.
-
Push changes to your repository to trigger the deployment.
-
Initialize Git repository:
git init -
Add files to Git:
git add . -
Commit changes:
git commit -m "Initial commit" -
Add GitHub remote:
git remote add origin https://github.com/yourusername/news-perspectives.git -
Push to GitHub:
git push -u origin main