Modifications

This commit is contained in:
stiti
2025-04-09 12:33:59 +02:00
parent 2b4bb321e2
commit 8a50b1c9cd
3 changed files with 12 additions and 11 deletions

View File

@@ -1,7 +1,3 @@
Lien meme de test : https://ichef.bbci.co.uk/ace/standard/976/cpsprodpb/16620/production/_91408619_55df76d5-2245-41c1-8031-07a4da3f313f.jpg
Lien URL serveur : http://localhost/index.html
# Configuration Docker Compose # Configuration Docker Compose
## Liens utiles ## Liens utiles

View File

@@ -1,6 +1,7 @@
from fastapi import FastAPI from fastapi import FastAPI
from pymongo import MongoClient from pymongo import MongoClient
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
import os
app = FastAPI() app = FastAPI()
@@ -21,8 +22,11 @@ app.add_middleware(
allow_headers=["*"], allow_headers=["*"],
) )
# MongoDB connection # Récupération des variables sans valeurs par défaut
client = MongoClient("mongodb://mongodb:27017/") mongo_service = os.environ["MONGO_SERVICE_NAME"]
mongo_port = os.environ["MONGO_PORT"]
mongo_uri = f"mongodb://{mongo_service}:{mongo_port}/"
client = MongoClient(mongo_uri)
db = client.memes_db db = client.memes_db
@app.get("/memes") @app.get("/memes")

View File

@@ -1,6 +1,6 @@
version: '3' version: '3'
services: services:
mongodb: db:
image: mongo:latest image: mongo:latest
volumes: volumes:
- mongo-data:/data/db - mongo-data:/data/db
@@ -10,9 +10,10 @@ services:
backend: backend:
build: ./backend build: ./backend
depends_on: depends_on:
- mongodb - db
environment: environment:
- MONGO_URI=mongodb://mongodb:27017/ - MONGO_SERVICE_NAME=db
- MONGO_PORT=27017
networks: networks:
- backend-network - backend-network
- frontend-network - frontend-network
@@ -30,9 +31,9 @@ services:
volumes: volumes:
mongo-data: mongo-data:
driver: local
# Pour la sécurité, c'est mieux d'avoir deux réseaux (vu en CM) -> même si dans notre cas ce n'est pas utile # Pour la sécurité, c'est mieux d'avoir deux réseaux (vu en CM) -> même si dans notre cas ce n'est pas utile + internal true isole le réseau
networks: networks:
backend-network: backend-network:
internal: true
frontend-network: frontend-network: