Files
app/nextjs/data/api.js
T
Sébastien GLATZ 96d599ba26 Revert "Modification page liste offres"
This reverts commit cf59b8cede, reversing
changes made to 0c5c702f78.

Retour en arrière pour enlever node modules
2019-05-27 12:56:05 +02:00

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;
}
}
}