CoolFace
Apppublic

qirang/nlip

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
apiClient.js21 linesDownload Raw Back to extension
1import { getStorage } from './storageUtils';2import { STORAGE_KEYS, AUTH_WHITELIST } from './constants';3 4export const makeRequest = async (request) => {5  const { [STORAGE_KEYS.SETTINGS]: nlipSettings } = await getStorage(STORAGE_KEYS.SETTINGS);6  const { [STORAGE_KEYS.TOKEN]: token } = await getStorage(STORAGE_KEYS.TOKEN);7  8  const defaultHeaders = {9    'Content-Type': 'application/json'10  };11 12  if (!AUTH_WHITELIST.includes(request.path)) {13    defaultHeaders.Authorization = `Bearer ${token}`;14  }15 16  return fetch(`${nlipSettings.url}${request.path}`, {17    method: request.method || 'GET',18    headers: { ...defaultHeaders, ...request.headers },19    body: request.body ? JSON.stringify(request.body) : undefined20  });21};