diff --git a/Dockerfile b/Dockerfile index 932bbae..808cbd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,12 @@ RUN npm install # Copie des fichiers source COPY . . -# Build de l'application (sans définir d'URL spécifique) +# Argument de build pour l'URL de l'API +ARG VITE_TEXTS_API_URL +ENV VITE_TEXTS_API_URL=${VITE_TEXTS_API_URL} + +# Build de l'application +RUN echo "Building with VITE_TEXTS_API_URL=$VITE_TEXTS_API_URL" RUN npm run build # Étape de production avec Nginx @@ -21,10 +26,6 @@ FROM nginx:alpine # Copie des fichiers buildés depuis l'étape précédente COPY --from=build /app/dist /usr/share/nginx/html -# Copie du script de configuration de l'API -COPY 30-api-config.sh /docker-entrypoint.d/30-api-config.sh -RUN chmod +x /docker-entrypoint.d/30-api-config.sh - # Exposition explicite du port utilisé par Nginx EXPOSE 80 diff --git a/backend/.env b/backend/.env new file mode 100644 index 0000000..8828fdc --- /dev/null +++ b/backend/.env @@ -0,0 +1 @@ +PORT=3000 \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index 2674953..c7d519d 100644 --- a/backend/server.js +++ b/backend/server.js @@ -21,7 +21,7 @@ app.use(cors()) app.use(express.json()) // Chemin vers le dossier texts (dossier parent) -const TEXTS_DIR = process.env.TEXTS_PATH || path.join(__dirname, '..', 'texts') +const TEXTS_DIR = process.env.TEXTS_PATH || "C:\\Users\\paulf\\Documents\\texts" /** * Service pour scanner et charger les textes depuis le dossier texts/ @@ -322,6 +322,15 @@ class TextService { categories: categories.size } } + + async getRandomText() { + const allTexts = await this.scanTexts() + if (allTexts.length === 0) { + throw new Error('Aucun texte disponible') + } + const randomIndex = Math.floor(Math.random() * allTexts.length) + return allTexts[randomIndex] + } } // Instance du service diff --git a/src/services/textService.js b/src/services/textService.js index 31d82bf..4955771 100644 --- a/src/services/textService.js +++ b/src/services/textService.js @@ -2,7 +2,7 @@ * Service pour communiquer avec l'API backend des textes */ -const API_BASE_URL = 'VITE_TEXTS_API_URL_PLACEHOLDER' +const API_BASE_URL = import.meta.env.VITE_TEXTS_API_URL || 'http://localhost:3000/api' export class TextService { constructor() { diff --git a/truenas-build.yml b/truenas-build.yml new file mode 100644 index 0000000..3ce5e16 --- /dev/null +++ b/truenas-build.yml @@ -0,0 +1,25 @@ +version: '3' + +services: + api: + image: elpoyo/patois-api:latest + restart: always + ports: + - '52000:3000' + environment: + - PORT=3000 + - TEXTS_PATH=/app/texts + - NODE_ENV=production + volumes: + - /mnt/Data/configs/patois:/app/texts + + frontend: + build: + context: . + args: + - VITE_TEXTS_API_URL=https://patois.lagaudiere.uk/api + restart: always + ports: + - '52001:80' + depends_on: + - api