fix(backend): switch OFF API to /cgi/search.pl endpoint and fix test imports
Run Tests on Branches / Detect Changes (push) Successful in 8s
Run Tests on Branches / Frontend Tests (push) Has been cancelled
Run Tests on Branches / Frontend Mobile Tests (push) Has been cancelled
Run Tests on Branches / Backend Tests (push) Has been cancelled

- 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:
Antoni Nuñez Romeu
2026-07-13 16:18:11 +02:00
parent 4df1594b3b
commit 26f309acfb
2 changed files with 58 additions and 43 deletions
+6 -6
View File
@@ -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) {