added logic to support self signed certs

This commit is contained in:
2025-04-15 19:23:42 -04:00
parent 21a6734300
commit 10983b9410
7 changed files with 33 additions and 59 deletions

View File

@@ -1,41 +1,14 @@
import os
import uuid
from functools import wraps
from flask import Flask, request, jsonify, send_from_directory
from werkzeug.utils import secure_filename
import requests
from dotenv import load_dotenv
import utils.mLogger as log
from controllers.file_controller import upload_file, download_file, delete_file
from views import views
# Get the project root directory (one level up from src)
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
env_path = os.path.join(project_root, '.env')
# Load environment variables with explicit path
load_dotenv(dotenv_path=env_path)
# Debug log for environment loading
log.i(f"Loading .env from: {env_path}")
log.i(f"File exists: {os.path.exists(env_path)}")
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'tmp/uploads'
app.config['CLIENT_KEY'] = os.getenv('CLIENT_KEY', 'default-secret-key')
# Log the loaded client key (masked)
if app.config['CLIENT_KEY']:
masked_key = app.config['CLIENT_KEY'][:4] + '*' * (len(app.config['CLIENT_KEY']) - 4)
log.i(f"Loaded client key: {masked_key}")
else:
log.w("No client key configured, using default")
# Log all environment variables (masked)
for key, value in os.environ.items():
if 'KEY' in key or 'SECRET' in key.upper():
masked = value[:4] + '*' * (len(value) - 4) if value else None
log.i(f"Env: {key}={masked}")
app.config['CLIENT_KEY'] = os.environ.get('CLIENT_KEY', 'default-secret-key')
if not os.path.exists(app.config['UPLOAD_FOLDER']):
os.makedirs(app.config['UPLOAD_FOLDER'])

19
src/start.py Normal file
View File

@@ -0,0 +1,19 @@
import os
import subprocess
cert = os.getenv("SSL_CERT", "cert.pem")
key = os.getenv("SSL_KEY", "key.pem")
use_ssl = os.path.exists(cert) and os.path.exists(key)
base_cmd = [
"gunicorn", "wsgi:app", "--bind", "0.0.0.0:7777"
]
if use_ssl:
print("🟢 Starting with HTTPS")
base_cmd += ["--certfile", cert, "--keyfile", key]
else:
print("🟡 Starting with HTTP (no certs found)")
subprocess.run(base_cmd)