43 lines
No EOL
1.7 KiB
Python
43 lines
No EOL
1.7 KiB
Python
import os
|
|
import tempfile
|
|
from flask import Flask
|
|
from flask_cors import CORS
|
|
from config import Config
|
|
from routes.api import api_bp
|
|
from routes.health import health_bp
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config.from_object(Config)
|
|
|
|
# Configure CORS - allow localhost in development
|
|
if Config.IS_DEVELOPMENT:
|
|
CORS(app,
|
|
origins=["http://localhost:3000", "http://127.0.0.1:3000", Config.FRONTEND_URL],
|
|
supports_credentials=True,
|
|
allow_headers=["Content-Type", "Authorization", "Access-Control-Allow-Credentials"],
|
|
methods=["GET", "POST", "DELETE", "OPTIONS"])
|
|
print(f"Development mode: CORS enabled for localhost:3000 and {Config.FRONTEND_URL}")
|
|
else:
|
|
CORS(app, origins=[Config.FRONTEND_URL])
|
|
print(f"Production mode: CORS enabled for {Config.FRONTEND_URL}")
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(health_bp, url_prefix='/')
|
|
app.register_blueprint(api_bp, url_prefix='/api')
|
|
|
|
# Create temp download directory
|
|
print(f"DEBUG: Creating temp directory at: {Config.TEMP_DOWNLOAD_PATH}")
|
|
os.makedirs(Config.TEMP_DOWNLOAD_PATH, exist_ok=True)
|
|
print(f"DEBUG: Temp directory exists: {os.path.exists(Config.TEMP_DOWNLOAD_PATH)}")
|
|
print(f"DEBUG: Temp directory is writable: {os.access(Config.TEMP_DOWNLOAD_PATH, os.W_OK)}")
|
|
|
|
# Set tempfile module to use our directory as default
|
|
tempfile.tempdir = Config.TEMP_DOWNLOAD_PATH
|
|
print(f"DEBUG: Set tempfile.tempdir to: {tempfile.tempdir}")
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(host='0.0.0.0', port=Config.PORT, debug=Config.FLASK_DEBUG) |