78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""
|
|
Main application entry point for CAE Mesh Generator
|
|
"""
|
|
from flask import Flask, request, jsonify
|
|
from config import FLASK_CONFIG
|
|
import os
|
|
|
|
def create_app():
|
|
"""Create and configure Flask application"""
|
|
app = Flask(__name__,
|
|
static_folder='frontend/static',
|
|
template_folder='frontend')
|
|
|
|
# Load configuration
|
|
app.config.update(FLASK_CONFIG)
|
|
|
|
# Register API blueprint
|
|
from backend.api.routes import api_bp
|
|
app.register_blueprint(api_bp, url_prefix='/api')
|
|
|
|
# Basic route for serving frontend
|
|
@app.route('/')
|
|
def index():
|
|
from flask import render_template
|
|
return render_template('index.html')
|
|
|
|
# Favicon route
|
|
@app.route('/favicon.ico')
|
|
def favicon():
|
|
return app.send_static_file('favicon.ico')
|
|
|
|
# Error handlers
|
|
@app.errorhandler(413)
|
|
def too_large(e):
|
|
return jsonify({
|
|
'success': False,
|
|
'error': 'File too large. Maximum size is 100MB.'
|
|
}), 413
|
|
|
|
@app.errorhandler(404)
|
|
def not_found(e):
|
|
if request.path.startswith('/api/'):
|
|
return jsonify({
|
|
'success': False,
|
|
'error': 'API endpoint not found'
|
|
}), 404
|
|
# Don't redirect favicon or other static file requests to index.html
|
|
if request.path.startswith('/favicon.ico') or request.path.startswith('/static/'):
|
|
return jsonify({
|
|
'success': False,
|
|
'error': 'File not found'
|
|
}), 404
|
|
# For other routes, serve the SPA
|
|
from flask import render_template
|
|
return render_template('index.html')
|
|
|
|
@app.errorhandler(500)
|
|
def internal_error(e):
|
|
return jsonify({
|
|
'success': False,
|
|
'error': 'Internal server error'
|
|
}), 500
|
|
|
|
# Register cleanup on app teardown
|
|
@app.teardown_appcontext
|
|
def cleanup_resources(error):
|
|
"""Clean up resources when app context is torn down"""
|
|
try:
|
|
from backend.utils.resource_manager import resource_manager
|
|
resource_manager.cleanup_temp_files()
|
|
except Exception as e:
|
|
app.logger.warning(f"Resource cleanup warning: {e}")
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(host='0.0.0.0', port=5000, debug=True) |