Skip to content

Commit

Permalink
Merge pull request #15 from GSG-G10/10-send-request-on-load-page
Browse files Browse the repository at this point in the history
10 send request on load page
  • Loading branch information
Raghad-Mezied authored Aug 11, 2021
2 parents ddb71e1 + cfec239 commit a125c8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
19 changes: 19 additions & 0 deletions public/assest/js/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const firstPopularPhoto = document.querySelector('.first-pop');
const secondePopularPhoto = document.querySelector('.seconde-pop');
const thirdPopularPhoto = document.querySelector('.third-pop');
const fourthPopularPhoto = document.querySelector('.fourth-pop');
const onLoadPage = (() => {
const changePopularImages = () => {
fetch('/popImages')
.then((response) => response.json())
.then((data) => {
console.log(data[0]);
firstPopularPhoto.src = data[0].thumbnail;
secondePopularPhoto.src = data[1].thumbnail;
thirdPopularPhoto.src = data[2].thumbnail;
fourthPopularPhoto.src = data[3].thumbnail;
})
.catch((err) => err);
};
changePopularImages();
})();
18 changes: 16 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@ app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
});

app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
const API_KEY = {
headers: {
'x-rapidapi-key': '469c1ee794msh8a7c6f3db2abd58p1e322ejsn1ead0ede256f',
'x-rapidapi-host': 'free-to-play-games-database.p.rapidapi.com',
},
};
app.get('/popImages', (req, res) => {
axios.request('https://free-to-play-games-database.p.rapidapi.com/api/games?sort-by=alphabetical', API_KEY)
.then((response) => response)
.then((response) => res.send([
response.data[0],
response.data[1],
response.data[2],
response.data[3],
]))
.catch((err) => res.send(err.message));
});

app.use(error404);
Expand Down

0 comments on commit a125c8a

Please sign in to comment.