fix(backend): switch OFF API to /cgi/search.pl endpoint and fix test imports
- Changed from /api/v2/search (returning 503) to /cgi/search.pl (working) - Removed strict categories_tags=baby-food filter that was too restrictive - Fixed test file to use dynamic imports for ES module compatibility - Increased timeout to 10s for reliability
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios from 'axios';
|
||||
import redisClient from './redis-client.js';
|
||||
|
||||
const OFF_API_BASE = 'https://world.openfoodfacts.org/api/v2';
|
||||
const OFF_API_BASE = 'https://world.openfoodfacts.org';
|
||||
const CACHE_TTL = 3600;
|
||||
|
||||
export function transformOFFProduct(offProduct) {
|
||||
@@ -53,15 +53,15 @@ export async function searchBabyProducts(query) {
|
||||
}
|
||||
|
||||
console.log(`Fetching from OFF API: ${searchTerm}`);
|
||||
const response = await axios.get(`${OFF_API_BASE}/search`, {
|
||||
const response = await axios.get(`${OFF_API_BASE}/cgi/search.pl`, {
|
||||
params: {
|
||||
categories_tags: 'baby-food',
|
||||
search_terms: searchTerm,
|
||||
json: true,
|
||||
fields: 'product_name,brands,image_url,nutriscore_grade,ingredients_text,nova_group,ecoscore_grade,categories_tags',
|
||||
page_size: 20,
|
||||
action: 'process',
|
||||
},
|
||||
timeout: 5000,
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
if (response.data && response.data.products) {
|
||||
@@ -100,8 +100,8 @@ export async function getBabyProductDetails(barcode) {
|
||||
}
|
||||
|
||||
console.log(`Fetching OFF product details: ${barcode}`);
|
||||
const response = await axios.get(`${OFF_API_BASE}/product/${barcode}.json`, {
|
||||
timeout: 5000,
|
||||
const response = await axios.get(`${OFF_API_BASE}/api/v2/product/${barcode}.json`, {
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
if (response.data && response.data.product) {
|
||||
|
||||
Reference in New Issue
Block a user