zkt25/z1/README.md
2025-03-19 11:44:50 +01:00

53 lines
1.6 KiB
Markdown

# Visitor Counter Application
This project demonstrates a simple web application using Apache (web server), Flask (backend) and Redis(database), deployed with Docker Compose.
## Prerequisites
- Docker Engine v20.10 or newer.
- Docker Compose v2.33.1 or newer.
## Application Description
The application consists of two services:
1. Web server (Apache) serving an HTML page.
2. Backend (flask): Handles requests to '/counter'.
2. Database (Redis) storing visitor counts persistently.
## Instructions
1. Prepare the application:
./prepare-app.sh
2. Start the application:
./start-app.sh
3. Access the application at:
http://localhost:5000
or
run "hostname -I " and copy the ip address and Access the application at :
http://[ip address you copied]:5000
4. Stop the application:
./stop-app.sh
5. Remove all resources:
./remove-app.sh
## Virtual netwok and volumes
- A default network is created by docker compose for communication between these services
- A named volum ('redis_data') ensures Redis data persists across restarts.
## Cross-Origin Resource Sharing (CORS)
Since the frontend (Apache) and backend (Flask) run on different ports, Cross-Origin Resource Sharing (CORS) has been enabled in the Flask backend using [`Flask-CORS`](https://flask-cors.readthedocs.io/en/latest/).
Specifically, the following configuration was added to the Flask backend (`app.py`):
from flask_cors import CORS
app = Flask(name)
CORS(app) # Enables CORS for all routes and origins
This allows the frontend JavaScript code to successfully communicate with the backend API without browser security restrictions.