From 948544fd286a12dc490fe5e35b02b6948eb845b2 Mon Sep 17 00:00:00 2001 From: Anton Wyrowski Date: Sun, 14 Jul 2024 10:23:00 +0200 Subject: [PATCH] fix: docker compose support --- docker-compose.yml | 2 ++ frontend/components/image-classification.tsx | 5 +++-- frontend/lib/config.ts | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 frontend/lib/config.ts diff --git a/docker-compose.yml b/docker-compose.yml index 2ae748a..79d2ea8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,8 @@ services: dockerfile: Dockerfile ports: - 3001:3000 + environment: + - NEXT_PUBLIC_API_URL=http://lens-api:5000 restart: always depends_on: - lens-api diff --git a/frontend/components/image-classification.tsx b/frontend/components/image-classification.tsx index 98821aa..a3063c2 100644 --- a/frontend/components/image-classification.tsx +++ b/frontend/components/image-classification.tsx @@ -1,5 +1,6 @@ 'use client'; +import Config from '@/lib/config'; import { ClassificationProduct, ClassificationProductDescription, @@ -39,7 +40,7 @@ export default function ImageClassification() { const formData = new FormData(); formData.append('file', image); - fetch('http://localhost:3002/classify', { + fetch(`${Config.apiUrl}/classify`, { method: 'POST', body: formData, }).then(async (response) => { @@ -128,7 +129,7 @@ function ClassificationCard({ data }: { data: ClassificationProduct }) { }; return ( -
+

{cardTitle[data.data_description]}

{buildCard}
diff --git a/frontend/lib/config.ts b/frontend/lib/config.ts new file mode 100644 index 0000000..b5b8f95 --- /dev/null +++ b/frontend/lib/config.ts @@ -0,0 +1,5 @@ +export default class Config { + static get apiUrl(): string { + return process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3002'; + } +}