96d599ba26
This reverts commitcf59b8cede, reversing changes made to0c5c702f78. Retour en arrière pour enlever node modules
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import fetch from 'isomorphic-unfetch'
|
|
|
|
//TODO: 'isomorphic-unfetch' :how to set default headers ?
|
|
// var obj = {
|
|
// method: 'GET',
|
|
// mode: 'no-cors',
|
|
// // headers: {
|
|
// // 'Access-Control-Request-Headers': 'Authorization',
|
|
// // 'Authorization': 'Basic amFzcGVyYWRtaW46amFzcGVyYWRtaW4=',
|
|
// // 'Content-Type': 'application/json',
|
|
// // 'Origin': ''
|
|
// // },
|
|
// credentials: 'include'
|
|
// };
|
|
|
|
export default {
|
|
ads: {
|
|
fetchAd: async (id) => {
|
|
const res = await fetch(`http://localhost/app_dev.php/api/ads/${id}`)
|
|
const offre = await res.json()
|
|
|
|
return { offre: offre.data }
|
|
},
|
|
fetchAds: async (limit = "", order = "", keyword = "", offset = 1) => {
|
|
var obj = {
|
|
method: 'GET',
|
|
//mode : 'no-cors',
|
|
headers: {
|
|
// 'Access-Control-Request-Headers': 'Authorization',
|
|
// 'Authorization': 'Basic amFzcGVyYWRtaW46amFzcGVyYWRtaW4=',
|
|
'Content-Type': 'application/json',
|
|
'Origin': ''
|
|
},
|
|
credentials: 'include'
|
|
};
|
|
|
|
let url = `http://localhost/app_dev.php/api/ads?offset=${offset}`;
|
|
if (limit != "") {
|
|
url = url + `&limit=${limit}`;
|
|
}
|
|
if (order != "") {
|
|
url = url + `&order=${order}`;
|
|
}
|
|
if (keyword != "") {
|
|
url = url + `&keyword=${keyword}`;
|
|
}
|
|
const res = await fetch(url, obj);
|
|
const show = await res.json();
|
|
return show.data;
|
|
}
|
|
|
|
}
|
|
} |