Added Moment module and got data imported into each card
This commit is contained in:
@@ -78,6 +78,13 @@ app.use(express.static(path.join(__dirname, 'resources')));
|
||||
// <!-- Section 4 : API Routes -->
|
||||
// *****************************************************
|
||||
|
||||
/************************
|
||||
Header Scoreboard Routes
|
||||
*************************/
|
||||
|
||||
const fetchMatchesData = require('./resources/js/scoreboard-header/current-match-routes');
|
||||
app.use(fetchMatchesData);
|
||||
|
||||
/************************
|
||||
Login Page Routes
|
||||
*************************/
|
||||
@@ -153,66 +160,12 @@ app.get('/', (req, res) => {
|
||||
});
|
||||
|
||||
/************************
|
||||
Scoreboard Header Routes
|
||||
Home Page Routes
|
||||
*************************/
|
||||
|
||||
// Connect to Premier League Matches API
|
||||
// Define a middleware function to fetch Premier League matches data
|
||||
app.get('/home', async (req, res) => {
|
||||
try
|
||||
{
|
||||
const today = moment().format('YYYY-MM-DD'); // Get today's date in YYYY-MM-DD format
|
||||
|
||||
const response = await axios({
|
||||
url: 'http://api.football-data.org/v4/competitions/2021/matches',
|
||||
method: 'GET',
|
||||
params:
|
||||
{
|
||||
dateFrom: '2024-04-03', // Set dateFrom to today's date
|
||||
dateTo: today // Set dateTo to today's date
|
||||
},
|
||||
headers:
|
||||
{
|
||||
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3' // Add your API key here
|
||||
}
|
||||
});
|
||||
|
||||
// Log the response data
|
||||
// console.log('API Response:', response.data);
|
||||
|
||||
const matches = response.data.matches.map(match => {
|
||||
let homeScore, awayScore, minute;
|
||||
|
||||
// Log match data
|
||||
console.log('Match Data:', {
|
||||
homeTeam: {
|
||||
name: match.homeTeam.name,
|
||||
crest: match.homeTeam.crest,
|
||||
},
|
||||
awayTeam: {
|
||||
name: match.awayTeam.name,
|
||||
crest: match.awayTeam.crest,
|
||||
},
|
||||
score: {
|
||||
homeScore: match.score.fullTime.home,
|
||||
awayScore: match.score.fullTime.away,
|
||||
},
|
||||
minute: match.status // Set the minute of the game
|
||||
});
|
||||
});
|
||||
|
||||
// Render the Homepage
|
||||
app.get('/home', (req, res) => {
|
||||
res.render('pages/home');
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.error('Error fetching Premier League matches:', error);
|
||||
res.status(500).json({ error: 'Internal Server Error' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
// *****************************************************
|
||||
// <!-- Section 5 : Start Server-->
|
||||
|
||||
Reference in New Issue
Block a user