Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_FOLKSONOMY_API_URL=https://api.folksonomy.openfoodfacts.net
VITE_OFF_BASE_URL=https://world.openfoodfacts.org
VITE_API_VERSION=3
3 changes: 2 additions & 1 deletion src/lib/api/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class ProductsApi {
}

async getProductAttributes(barcode: string): Promise<ProductAttribute[]> {
const url = `${API_HOST}/api/v2/product/${barcode}?fields=product_name,code,attribute_groups_en`;
const apiVersion = import.meta.env.VITE_API_VERSION || '2';
const url = `${API_HOST}/api/v${apiVersion}/product/${barcode}?fields=product_name,code,attribute_groups_en`;

const res = await this.fetch(url);

Expand Down
5 changes: 4 additions & 1 deletion src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ export const USER_AGENT = `Open Food Facts Explorer (${import.meta.env.PACKAGE_V

export const KP_ATTRIBUTE_IMG = (img: string) => `${STATIC_HOST}/images/attributes/dist/${img}`;
export const TAXONOMY_URL = (taxo: string) => `${STATIC_HOST}/data/taxonomies/${taxo}.json`;
export const PRODUCT_URL = (barcode: string) => `${API_HOST}/api/v3/product/${barcode}.json`;
export const PRODUCT_URL = (barcode: string) => {
const apiVersion = import.meta.env.VITE_API_VERSION || '3';
return `${API_HOST}/api/v${apiVersion}/product/${barcode}.json`;
};
export const PRODUCT_IMAGE_URL = (path: string) => `${IMAGE_HOST}/images/products/${path}`;