A clean, modern, and secure news aggregation website built with HTML, CSS, and JavaScript. Features real-time news updates from NewsData.io API with comprehensive security measures and responsive design.
This application requires your own configuration to run:
- Get your own FREE API key from NewsData.io
- Deploy your own instance to Vercel (free)
- Update configuration with your URLs
You cannot use the demo URLs directly. See Installation & Setup below for complete instructions.
- Single-Page Application - Modern SPA architecture with URL parameter routing
- Real-time News Updates - Fetches latest news from NewsData.io API
- Multiple Categories - Home, International, Business, Sports, Entertainment, Technology
- Search Functionality - Search news by keywords with dedicated results view
- Responsive Design - Mobile-friendly interface that works on all devices
- Load More - Pagination support for browsing more articles
- Security Hardened - Protected against XSS, open redirects, and other vulnerabilities
- Error Handling - Graceful error messages with retry functionality
- Image Fallbacks - Placeholder images for broken URLs
- Loading States - Visual feedback during data fetching
- Clean URLs - SEO-friendly URLs with category parameters (
/?category=business)
Note: This project is deployed on Vercel with a custom subdomain:
- Primary Site: Custom domain on Vercel (includes frontend + API)
- API Proxy: Vercel serverless function (keeps API key secure)
- Backup: GitHub Pages deployment (fallback)
Live Site: https://news.aparagarwal.tech/
GitHub Pages (Backup): https://aparagarwal.tech/News-Website/
To deploy your own instance, you'll need your own NewsData.io API key and Vercel deployment. See Installation & Setup below.
- Frontend: HTML5, CSS3, Vanilla JavaScript
- API: NewsData.io
- Hosting: Vercel (custom subdomain
news.aparagarwal.tech) - API Proxy: Vercel Serverless Functions
- Backup Hosting: GitHub Pages
News-Website/
βββ index.html # Single-page application (all categories)
βββ README.md # Project documentation
βββ .gitignore # Git ignore rules
βββ .env.example # Environment variables template
βββ vercel.json # Vercel configuration
β
βββ api/ # Serverless functions
β βββ news.js # API proxy for secure requests
β
βββ js/ # JavaScript files
β βββ script.js # Main application logic with URL routing
β βββ utils.js # Utility and security functions
β
βββ css/ # Stylesheets
β βββ style.css # Main stylesheet
β
βββ assets/ # Static assets
β βββ favicon_io/ # Favicon files
β βββ icon.png # Site icon
β βββ logo.png # Site logo
β βββ placeholder.svg # Fallback image for broken URLs
β
βββ docs/ # Documentation
βββ DEPLOYMENT.md # Deployment guide
βββ LOCAL_SETUP.md # Local development setup
βββ ENVIRONMENT.md # Environment configuration
βββ CUSTOM_DOMAIN.md # Custom domain setup
Single-Page Application (SPA):
The app uses URL parameters for routing instead of multiple HTML files:
- Home:
/or/?category=home - Categories:
/?category=business,/?category=sports, etc. - Search:
/?q=query
JavaScript dynamically loads content based on URL parameters, eliminating code duplication and improving maintainability.
β οΈ IMPORTANT: This application requires your own API key and Vercel deployment. You cannot use the demo URLs directly. Follow the setup instructions below.
Before you begin, you'll need:
- A free NewsData.io API key (Sign up here)
- A GitHub account
- A Vercel account (Sign up free)
Step 1: Fork the Repository
- Click the "Fork" button at the top right of this repository
- Clone your forked repository:
git clone https://github.com/YOUR_USERNAME/News-Website.git cd News-Website
Step 2: Get Your API Key
- Go to https://newsdata.io/
- Sign up for a free account
- Get your API key from the dashboard
- Save it for the next step
Step 3: Deploy to Vercel
- Go to vercel.com and sign in with GitHub
- Click "Add New..." β "Project"
- Import your forked
News-Websiterepository - In Environment Variables, add:
- Name:
NEWS_API_KEY - Value: Your NewsData.io API key
- Name:
- Click Deploy and wait for deployment to complete
Step 4: Update Configuration
After Vercel deployment, you'll get a URL like: https://your-news-app.vercel.app
Update these files in your repository:
-
Edit
js/script.js(line 22):// Replace this: const VERCEL_FUNCTION_URL = 'YOUR_VERCEL_DEPLOYMENT_URL/api/news'; // With your actual URL: const VERCEL_FUNCTION_URL = 'https://your-news-app.vercel.app/api/news';
-
Edit
api/news.js(line 10) - Optional but recommended for production:// Replace this: res.setHeader('Access-Control-Allow-Origin', '*'); // With your actual URL: res.setHeader('Access-Control-Allow-Origin', 'https://your-news-app.vercel.app');
-
Commit and Push:
git add . git commit -m "config: add my Vercel deployment URL" git push origin main
Vercel will automatically redeploy with your changes!
Step 5: Access Your Site
Visit your Vercel URL: https://your-news-app.vercel.app π
For local testing and development, see the comprehensive guide:
π Local Setup Guide
The local setup guide covers:
- Running the project locally with Live Server or Python HTTP server
- Testing features during development
- Troubleshooting common issues
- Development workflow and best practices
Note: Local development automatically uses the deployed Vercel API proxy, so you don't need to set up environment variables locally.
For detailed deployment instructions, see: docs/DEPLOYMENT.md
This project implements multiple security best practices:
- β XSS Protection - All user-generated content is safely rendered using DOM manipulation
- β URL Validation - Prevents open redirect attacks by validating all external links
- β API Key Security - API keys stored in secure environment variables (Vercel deployment)
- β CORS Configuration - Proper CORS headers for API requests
- β
Secure External Links - All external links use
rel="noopener noreferrer" - β Input Sanitization - All user inputs are properly encoded
- β Error Boundaries - Comprehensive error handling prevents data leaks
Edit api/news.js to use a different news API:
const apiUrl = 'https://your-api-provider.com/endpoint';Modify css/style.css to customize the appearance:
- Colors: Update color variables
- Fonts: Change font imports at the top
- Layout: Adjust responsive breakpoints
Add new categories by:
- Adding navigation link to
index.htmlwithdata-categoryattribute - Adding category title mapping to
updatePageTitle()function injs/script.js - Adding category API mapping if needed (e.g.,
internationalβworld)
- β Chrome (latest)
- β Firefox (latest)
- β Safari (latest)
- β Edge (latest)
- β Mobile browsers (iOS Safari, Chrome Mobile)
- Initial cold start may take 2-3 seconds with Vercel Functions (free tier)
- Some news sources may have rate limits
- API provides limited results per request (pagination required for more articles)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available under the MIT License.
Apar Agarwal
- GitHub: @AparAgarwal
- LinkedIn: @aparagarwal
- News data provided by NewsData.io
- Icons from Boxicons
- Fonts from Google Fonts
- Deployment Guide - Detailed Vercel deployment instructions
- API Documentation - NewsData.io API docs
- π Major Refactor: Converted to Single-Page Application (SPA)
- β¨ Implemented URL parameter-based routing
- β¨ Reduced codebase by 86% (7 HTML files β 1 HTML file)
- β¨ Added dynamic navigation state management
- β¨ Improved SEO with clean, descriptive URLs
- β¨ Added search results view with hidden hero section
- β¨ Enhanced maintainability with centralized layout
- β¨ Implemented comprehensive security fixes
- β¨ Added Vercel serverless function for API proxy
- β¨ Improved error handling and loading states
- β¨ Added image fallback placeholders
- β¨ Refactored code structure for better maintainability
- β¨ Added proper documentation
- π Initial release
- Basic news aggregation functionality
- Responsive design implementation
Made with β€οΈ by Apar Agarwal

