This project is a serverless proxy server for the News API, designed to fetch and serve news articles securely. It's built to be deployed on Netlify and provides a simple API for retrieving top headlines and searching for news articles.
- Fetch top headlines for specific news categories
- Search for news articles based on keywords
- Pagination support for both endpoints
- CORS-enabled for cross-origin requests
- Serverless architecture for easy deployment and scaling
- Node.js
- Express.js
- Axios for HTTP requests
- Serverless-http for serverless deployment
- CORS middleware for handling cross-origin requests
- Netlify for hosting and serverless functions
-
Clone the repository: git clone https://github.com/SID9927/news-proxy-server.git
-
Navigate to the project directory: cd news-proxy-server
-
Install dependencies: npm install
-
Set up your News API key:
- Sign up for an API key at NewsAPI.org
- Set the
NEWS_API_KEYenvironment variable in your Netlify deployment settings
- Deploy to Netlify:
- Connect your GitHub repository to Netlify
- Netlify will automatically deploy your project using the settings in
netlify.toml
The proxy server provides two main endpoints:
-
Fetch top headlines: GET /api/news?category={category}&pageSize={pageSize}&page={page}
-
Search for news articles: GET /api/search?q={query}&pageSize={pageSize}&page={page}
Replace {category}, {query}, {pageSize}, and {page} with appropriate values.
functions/api.js: Main serverless function containing the Express app and API routesnetlify.toml: Netlify configuration file for build settings and redirectspackage.json: Project dependencies and scripts
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.