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
## Liens utiles

View File

@@ -1,6 +1,7 @@
from fastapi import FastAPI
from pymongo import MongoClient
from fastapi.middleware.cors import CORSMiddleware
import os
app = FastAPI()
@@ -21,8 +22,11 @@ app.add_middleware(
allow_headers=["*"],
)
# MongoDB connection
client = MongoClient("mongodb://mongodb:27017/")
# Récupération des variables sans valeurs par défaut
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
@app.get("/memes")

View File

@@ -1,6 +1,6 @@
version: '3'
services:
mongodb:
db:
image: mongo:latest
volumes:
- mongo-data:/data/db
@@ -10,9 +10,10 @@ services:
backend:
build: ./backend
depends_on:
- mongodb
- db
environment:
- MONGO_URI=mongodb://mongodb:27017/
- MONGO_SERVICE_NAME=db
- MONGO_PORT=27017
networks:
- backend-network
- frontend-network
@@ -30,9 +31,9 @@ services:
volumes:
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:
backend-network:
internal: true
frontend-network: