From 947ac0daf014ca199a089d36b947e19ee18d3c46 Mon Sep 17 00:00:00 2001 From: szbk Date: Tue, 11 Nov 2025 00:49:51 +0300 Subject: [PATCH] =?UTF-8?q?OcrStep=20bile=C5=9Feninde=20BASE=5FURL=20kontr?= =?UTF-8?q?ol=C3=BC=20g=C3=BCncellendi;=20Dockerfile=20ve=20docker-compose?= =?UTF-8?q?.yml=20dosyalar=C4=B1=20eklendi;=20geli=C5=9Ftirme=20ve=20?= =?UTF-8?q?=C3=BCretim=20ortamlar=C4=B1=20i=C3=A7in=20yap=C4=B1land=C4=B1r?= =?UTF-8?q?malar=20olu=C5=9Fturuldu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 27 +++++++++++++ docker-compose.yml | 62 ++++++++++++++++++++++++++++++ public/tesseract/worker.min.js.map | 1 + server/Dockerfile | 19 +++++++++ src/components/OcrStep.jsx | 22 +++++++---- 5 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 public/tesseract/worker.min.js.map create mode 100644 server/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d573e9c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# syntax=docker/dockerfile:1.6 + +ARG NODE_VERSION=20 + +FROM node:${NODE_VERSION}-alpine AS base +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . + +FROM base AS dev +ENV NODE_ENV=development +CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "5173"] + +FROM base AS build +ARG VITE_API_BASE_URL=http://localhost:4000 +ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} +RUN npm run build + +FROM node:${NODE_VERSION}-alpine AS prod +WORKDIR /app +ENV NODE_ENV=production +COPY package.json package-lock.json ./ +COPY --from=base /app/node_modules ./node_modules +COPY --from=build /app/dist ./dist +EXPOSE 4173 +CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "4173"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e5cdd44 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,62 @@ +services: + frontend-dev: + build: + context: . + target: dev + environment: + - VITE_API_BASE_URL=http://localhost:4000 + ports: + - "5173:5173" + volumes: + - .:/app + - frontend_dev_node_modules:/app/node_modules + depends_on: + - backend-dev + profiles: + - imgpub-app-dev + + backend-dev: + build: + context: ./server + target: dev + environment: + - PORT=4000 + - CLIENT_ORIGIN=http://localhost:5173 + ports: + - "4000:4000" + volumes: + - ./server:/app + - backend_dev_node_modules:/app/node_modules + profiles: + - imgpub-app-dev + + frontend-prod: + build: + context: . + target: prod + args: + VITE_API_BASE_URL: http://localhost:4000 + environment: + - VITE_API_BASE_URL=http://localhost:4000 + ports: + - "4173:4173" + depends_on: + - backend-prod + profiles: + - imgpub-app + + backend-prod: + build: + context: ./server + target: prod + environment: + - PORT=4000 + - CLIENT_ORIGIN=http://localhost:4173 + ports: + - "4000:4000" + profiles: + - imgpub-app + +volumes: + frontend_dev_node_modules: + backend_dev_node_modules: diff --git a/public/tesseract/worker.min.js.map b/public/tesseract/worker.min.js.map new file mode 100644 index 0000000..fad8aed --- /dev/null +++ b/public/tesseract/worker.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"worker.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":""} diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..4e75254 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,19 @@ +# syntax=docker/dockerfile:1.6 + +ARG NODE_VERSION=20 + +FROM node:${NODE_VERSION}-alpine AS base +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY . . + +FROM base AS dev +ENV NODE_ENV=development +EXPOSE 4000 +CMD ["npm", "run", "dev"] + +FROM base AS prod +ENV NODE_ENV=production +EXPOSE 4000 +CMD ["node", "index.js"] diff --git a/src/components/OcrStep.jsx b/src/components/OcrStep.jsx index 0d7d8ae..7081687 100644 --- a/src/components/OcrStep.jsx +++ b/src/components/OcrStep.jsx @@ -27,8 +27,11 @@ const OcrStep = () => { const abortRef = useRef(false); const assetBase = useMemo(() => { - const base = import.meta.env.BASE_URL ?? '/'; - return base.endsWith('/') ? base.slice(0, -1) : base; + const rawBase = import.meta.env.BASE_URL ?? '/'; + if (rawBase === '.' || rawBase === './' || rawBase === '/') { + return ''; + } + return rawBase.endsWith('/') ? rawBase.slice(0, -1) : rawBase; }, []); const workerRef = useRef(null); const [workerReady, setWorkerReady] = useState(false); @@ -54,15 +57,18 @@ const OcrStep = () => { const initWorker = async () => { setWorkerReady(false); try { + const workerOptions = { + workerPath: paths.workerPath, + corePath: paths.corePath, + langPath: paths.langPath, + }; + if (isDev) { + workerOptions.logger = (m) => console.log('Tesseract:', m); + } const worker = await Tesseract.createWorker( 'tur', // Dil doğrudan belirt 1, // OEM level (LSTM) - { - workerPath: paths.workerPath, - corePath: paths.corePath, - langPath: paths.langPath, - logger: isDev ? (m) => console.log('Tesseract:', m) : undefined, - }, + workerOptions, ); // Türkçe karakter tanımını iyileştir