// routes/articleRoutes.js
const express = require("express");
const { getArticles, addArticle } = require("../controllers/articleController");
const router = express.Router();
const authenticateToken = require("../middlewares/authMiddleware");

// Routes
router.get("/", getArticles);
router.post("/add", authenticateToken, addArticle);

module.exports = router;
// controllers/articleController.js
const Article = require("../models/articleModel");

// Fetch all articles
const getArticles = async (req, res) => {
  try {
    const articles = await Article.find();
    res.json(articles);
  } catch (error) {
    res.status(500).json({ error: "Error fetching articles" });
  }
};

// Add a new article
const addArticle = async (req, res) => {
  try {
    const { title, content, author } = req.body;
    const newArticle = new Article({ title, content, author });
    await newArticle.save();
    res.json(newArticle);
  } catch (error) {
    res.status(500).json({ error: "Error adding article" });
  }
};

module.exports = { getArticles, addArticle };

This is my and articleRoutes.js and  articleController.js 
const express = require("express");
const { getCountries, getLeagues } = require("../controllers/newsController");
const router = express.Router();

// Route to get countries
router.get("/countries", getCountries);

// Route to get leagues
router.get("/leagues", getLeagues);

module.exports = router;
require("dotenv").config();
const axios = require("axios");

// API Base URL and headers from RapidAPI
const BASE_URL = "https://sport-highlights-api.p.rapidapi.com";
const API_HOST = "sport-highlights-api.p.rapidapi.com";
const API_KEY = process.env.RAPID_API_KEY;

// Function to fetch all countries supported by the API
const getCountries = async (req, res) => {
  try {
    const response = await axios.get(`${BASE_URL}/football/countries`, {
      headers: {
        "x-rapidapi-key": API_KEY,
        "x-rapidapi-host": API_HOST,
      },
    });

    // Send the response data to the client
    res.status(200).json(response.data);
  } catch (error) {
    console.error("Error fetching countries:", error.message);
    res.status(500).json({ message: "Internal server error" });
  }
};

// Function to fetch football leagues
const getLeagues = async (req, res) => {
  const { countryCode, limit = 100 } = req.query;

  try {
    const response = await axios.get(`${BASE_URL}/football/leagues`, {
      params: {
        countryCode, // Optionally filter leagues by country code
        limit, // Limit the number of returned leagues
      },
      headers: {
        "x-rapidapi-key": API_KEY,
        "x-rapidapi-host": API_HOST,
      },
    });

    // Send the leagues data to the client
    res.status(200).json(response.data);
  } catch (error) {
    console.error("Error fetching leagues:", error.message);
    res.status(500).json({ message: "Internal server error" });
  }
};

// Export the functions to use in routes
module.exports = {
  getCountries,
  getLeagues,
};
require("dotenv").config();
const axios = require("axios");

// API Base URL and headers from RapidAPI
const BASE_URL = "https://sport-highlights-api.p.rapidapi.com";
const API_HOST = "sport-highlights-api.p.rapidapi.com";
const API_KEY = process.env.RAPID_API_KEY;

// Function to fetch all countries supported by the API
const getCountries = async (req, res) => {
  try {
    const response = await axios.get(`${BASE_URL}/football/countries`, {
      headers: {
        "x-rapidapi-key": API_KEY,
        "x-rapidapi-host": API_HOST,
      },
    });

    // Send the response data to the client
    res.status(200).json(response.data);
  } catch (error) {
    console.error("Error fetching countries:", error.message);
    res.status(500).json({ message: "Internal server error" });
  }
};

// Function to fetch football leagues
const getLeagues = async (req, res) => {
  const { countryCode, limit = 100 } = req.query;

  try {
    const response = await axios.get(`${BASE_URL}/football/leagues`, {
      params: {
        countryCode, // Optionally filter leagues by country code
        limit, // Limit the number of returned leagues
      },
      headers: {
        "x-rapidapi-key": API_KEY,
        "x-rapidapi-host": API_HOST,
      },
    });

    // Send the leagues data to the client
    res.status(200).json(response.data);
  } catch (error) {
    console.error("Error fetching leagues:", error.message);
    res.status(500).json({ message: "Internal server error" });
  }
};

// Export the functions to use in routes
module.exports = {
  getCountries,
  getLeagues,
};
This my newsRoutes.js and newsController.js 
What I want is to make newController.js and articleController.js 
Such that it fetches news and from API 
curl --request GET \
	--url https://football-news-aggregator-live.p.rapidapi.com/news/fourfourtwo/bundesliga \
	--header 'x-rapidapi-host: football-news-aggregator-live.p.rapidapi.com' \
	--header 'x-rapidapi-key: Sign Up for Key'
Like this I'll provide Rapid API key in my .env file 
curl --request GET \
	--url https://football-news-aggregator-live.p.rapidapi.com/news/fourfourtwo/ucl \
	--header 'x-rapidapi-host: football-news-aggregator-live.p.rapidapi.com' \
	--header 'x-rapidapi-key: Sign Up for Key'
curl --request GET \
	--url https://football-news-aggregator-live.p.rapidapi.com/news \
	--header 'x-rapidapi-host: football-news-aggregator-live.p.rapidapi.com' \
	--header 'x-rapidapi-key: Sign Up for Key'
This is allnews which will appear to them 
Make it happen in a controller for article and news 
and based on that sort the news in data format