2018-10-19 05:15:28 +00:00
|
|
|
const functions = require('firebase-functions');
|
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
axios.defaults.headers.common['user-key'] = functions.config().igdb.key;
|
|
|
|
|
|
|
|
const igdbUrl = 'https://api-endpoint.igdb.com';
|
|
|
|
|
|
|
|
exports.search = functions.https.onRequest((req, res) => {
|
2018-10-19 06:00:49 +00:00
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
2018-10-19 05:15:28 +00:00
|
|
|
const { searchText, platformId } = req.query;
|
|
|
|
|
2018-11-02 01:41:25 +00:00
|
|
|
axios.get(`${igdbUrl}/games/?search=${searchText}&fields=id,name,slug,created_at,updated_at,summary,rating,category,player_perspectives,release_dates,name,cover,platforms,screenshots,videos,websites,esrb,pegi,themes.name,game.name&expand=game,themes,developers,publishers,game_engines,game_modes,genres,platforms,player_perspectives&filter[platforms][eq]=${platformId}&limit=20&order=popularity:desc`)
|
2018-10-19 05:15:28 +00:00
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
|
|
.catch(() => { res.send(400) });
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.games = functions.https.onRequest((req, res) => {
|
2018-10-19 06:00:49 +00:00
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
2018-10-19 05:15:28 +00:00
|
|
|
const { games, platformId } = req.query;
|
|
|
|
|
|
|
|
axios.get(`${igdbUrl}/games/${games}/?fields=id,name,slug,created_at,updated_at,summary,rating,category,player_perspectives,release_dates,name,cover,platforms,screenshots,videos,websites,esrb,pegi,themes.name,game.name&expand=game,themes,developers,publishers,game_engines,game_modes,genres,platforms,player_perspectives`)
|
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
|
|
.catch(() => { res.send(400) });
|
|
|
|
});
|
2018-10-25 06:33:15 +00:00
|
|
|
|
|
|
|
exports.platform = functions.https.onRequest((req, res) => {
|
|
|
|
res.set('Access-Control-Allow-Origin', "*")
|
|
|
|
|
|
|
|
const { platformId } = req.query;
|
|
|
|
|
|
|
|
axios.get(`${igdbUrl}/platforms/${platformId}`)
|
|
|
|
.then(({ data }) => { res.status(200).send(data) })
|
|
|
|
.catch(() => { res.send(400) });
|
|
|
|
});
|