Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ cp .env.example .env

Edit the `.env` file as needed to configure your development environment.

#### Development Configuration

- Set `VITE_API_VERSION` in `.env` file to test different versions of the Open Food Facts API (default: 3)
- For example, to test the API v2: `VITE_API_VERSION=2`
- This is useful for testing new API versions before updating the default version used in the application.

Then start the development server:

```bash
Expand Down
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 || '3';
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}`;