Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
631 B
3
Indexable
Never
export function mealsOrDrinks() {
  let END_POINT = '';
  const END_POINT_MEALS = 'https://www.themealdb.com/api/json/v1/1/filter.php?';
  const END_POINT_DRINKS = 'https://www.thecocktaildb.com/api/json/v1/1/filter.php?';

  switch (window.location.pathname) {
    case '/meals':
      END_POINT = END_POINT_MEALS;
      break;
    case '/drinks':
      END_POINT = END_POINT_DRINKS;
      break;
    default:
      return false;
  }
  async function api(ingrediente: string, tipo: string) {
    const response = await fetch(`${END_POINT}${tipo}=${ingrediente}`);
    const data = await response.json();
    return data.meals;
  }