Files
freeplanet/src/store/Api/Inst-Pao.ts
Paolo Arena 259e2dc4e2 ++ If press DELETE or BACKSPACE and is blank description, delete the Todos.
- fix: if offline, doesn't save to cache??  if I refresh page, the data disappear
- ++ field to the percent progress
- fix: Refreshing 2 times the array todos.. because there is a filter
2019-02-12 19:09:43 +01:00

51 lines
1.2 KiB
TypeScript

import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
async function sendRequest(url: string, lang: string, mytok: string, method: string, mydata: any) {
console.log('sendRequest', method, url, '[', lang, ']')
const authHeader = new Headers()
authHeader.append('content-Type', 'application/json')
authHeader.append('Accept', 'application/json')
if (url !== process.env.MONGODB_HOST + '/users/login') {
authHeader.append('x-auth', mytok)
// console.log('TOK PASSATO ALLA FETCH:', mytok)
}
// authHeader.append('accept-language', lang)
let configInit: RequestInit
if (method === 'GET') {
configInit = {
method: method,
cache: 'no-cache',
mode: 'cors',
headers: authHeader
}
} else if (method === 'DELETE') {
configInit = {
method: method,
cache: 'no-cache',
mode: 'cors',
headers: authHeader
}
} else {
configInit = {
method: method,
cache: 'no-cache',
mode: 'cors',
headers: authHeader
}
if (mydata !== null)
configInit.body = JSON.stringify(mydata)
}
const request: Promise<Response> = fetch(url, configInit)
return request
}
export default sendRequest