OcrStep bileşeninde BASE_URL kontrolü güncellendi; Dockerfile ve docker-compose.yml dosyaları eklendi; geliştirme ve üretim ortamları için yapılandırmalar oluşturuldu.

This commit is contained in:
2025-11-11 00:49:51 +03:00
parent 3a82bf9ea6
commit 947ac0daf0
5 changed files with 123 additions and 8 deletions

27
Dockerfile Normal file
View File

@@ -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"]

62
docker-compose.yml Normal file
View File

@@ -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:

View File

@@ -0,0 +1 @@
{"version":3,"file":"worker.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}

19
server/Dockerfile Normal file
View File

@@ -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"]

View File

@@ -27,8 +27,11 @@ const OcrStep = () => {
const abortRef = useRef(false); const abortRef = useRef(false);
const assetBase = useMemo(() => { const assetBase = useMemo(() => {
const base = import.meta.env.BASE_URL ?? '/'; const rawBase = import.meta.env.BASE_URL ?? '/';
return base.endsWith('/') ? base.slice(0, -1) : base; if (rawBase === '.' || rawBase === './' || rawBase === '/') {
return '';
}
return rawBase.endsWith('/') ? rawBase.slice(0, -1) : rawBase;
}, []); }, []);
const workerRef = useRef(null); const workerRef = useRef(null);
const [workerReady, setWorkerReady] = useState(false); const [workerReady, setWorkerReady] = useState(false);
@@ -54,15 +57,18 @@ const OcrStep = () => {
const initWorker = async () => { const initWorker = async () => {
setWorkerReady(false); setWorkerReady(false);
try { 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( const worker = await Tesseract.createWorker(
'tur', // Dil doğrudan belirt 'tur', // Dil doğrudan belirt
1, // OEM level (LSTM) 1, // OEM level (LSTM)
{ workerOptions,
workerPath: paths.workerPath,
corePath: paths.corePath,
langPath: paths.langPath,
logger: isDev ? (m) => console.log('Tesseract:', m) : undefined,
},
); );
// Türkçe karakter tanımını iyileştir // Türkçe karakter tanımını iyileştir