pridanie zakladnych funkcionalít

This commit is contained in:
tpikna
2026-04-14 21:00:08 +02:00
parent 8dac76c758
commit 462205c14c
6 changed files with 123 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py .
EXPOSE 5000
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "main:app"]

View File

@@ -0,0 +1,47 @@
import os
from flask import Flask, request, jsonify
from flask_mail import Mail, Message
from flask_cors import CORS
app = Flask(__name__)
# Povolenie CORS, aby mohol frontend (napr. z portu 80 alebo 8080) komunikovať s týmto API
CORS(app)
# Konfigurácia Flask-Mail pomocou premenných prostredia
app.config['MAIL_SERVER'] = os.environ.get('MAIL_SERVER', 'smtp.gmail.com')
app.config['MAIL_PORT'] = int(os.environ.get('MAIL_PORT', 587))
app.config['MAIL_USE_TLS'] = os.environ.get('MAIL_USE_TLS', 'True').lower() in ['true', '1', 't']
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME') # Tvoj email (napr. z ktoreho sa to odosiela)
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD') # Heslo k emailu alebo App Password
app.config['MAIL_DEFAULT_SENDER'] = os.environ.get('MAIL_DEFAULT_SENDER', app.config['MAIL_USERNAME'])
mail = Mail(app)
@app.route('/send-email', methods=['POST'])
def send_email():
data = request.json
if not data:
return jsonify({"error": "Neboli poskytnuté žiadne dáta"}), 400
name = data.get('name')
email = data.get('email')
message = data.get('message')
if not name or not email or not message:
return jsonify({"error": "Chýbajú povinné polia (meno, email, správa)"}), 400
try:
msg = Message(
subject=f"Nová správa z webu gobas.sk od: {name}",
recipients=[app.config['MAIL_USERNAME']], # Email ti príde na tvoju adresu
body=f"Meno: {name}\nEmail: {email}\n\nSpráva:\n{message}",
reply_to=email # Aby si mohol na email priamo odpovedať klientovi
)
mail.send(msg)
return jsonify({"message": "Email bol úspešne odoslaný!"}), 200
except Exception as e:
return jsonify({"error": f"Nastala chyba pri odosielaní: {str(e)}"}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

View File

@@ -0,0 +1,5 @@
Flask==3.0.0
Flask-Mail==0.9.1
Flask-Cors==4.0.0
gunicorn==21.2.0
python-dotenv==1.0.0

View File

@@ -0,0 +1,32 @@
services:
proxy:
image: nginx:alpine
container_name: gobas_proxy
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- frontend
- backend
restart: unless-stopped
frontend:
build:
context: ./frontned
dockerfile: Dockerfile
container_name: gobas_frontend
restart: unless-stopped
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: gobas_backend
environment:
- MAIL_SERVER=smtp.gmail.com
- MAIL_PORT=587
- MAIL_USE_TLS=True
- MAIL_USERNAME=${MAIL_USERNAME:-tvoj@email.sk}
- MAIL_PASSWORD=${MAIL_PASSWORD:-tvojeheslo}
restart: unless-stopped

5
frontned/Dockerfile Normal file
View File

@@ -0,0 +1,5 @@
FROM nginx:alpine
COPY src/ /usr/share/nginx/html/
EXPOSE 80

22
frontned/nginx.conf Normal file
View File

@@ -0,0 +1,22 @@
server {
listen 80;
server_name localhost;
# Smerovanie verejnej prevádzky na frontend kontajner
location / {
proxy_pass http://frontend:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Smerovanie API volaní na backend kontajner
location /api/ {
rewrite ^/api/(.*) /$1 break; # Odstráni /api/ z URL pred odoslaním do Flasku
proxy_pass http://backend:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}