NO docker
This commit is contained in:
64
app/root.py
Normal file
64
app/root.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Root routes and static file serving for SPA in production.
|
||||
|
||||
These were originally defined in the top-level app.py. Moving them into the
|
||||
package allows a clean WSGI entry (wsgi:app) without importing app.py.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, current_app, send_from_directory
|
||||
|
||||
root_bp = Blueprint('root', __name__)
|
||||
|
||||
|
||||
@root_bp.route('/')
|
||||
def index():
|
||||
try:
|
||||
return send_from_directory('/app/static', 'index.html')
|
||||
except Exception:
|
||||
# Fallback API info when frontend is not present
|
||||
return {
|
||||
'application': 'PANJIT Document Translator',
|
||||
'version': '1.0.0',
|
||||
'status': 'running',
|
||||
'api_base_url': '/api/v1',
|
||||
'note': 'Frontend files not found, serving API info'
|
||||
}
|
||||
|
||||
|
||||
@root_bp.route('/<path:path>')
|
||||
def serve_static(path):
|
||||
try:
|
||||
return send_from_directory('/app/static', path)
|
||||
except Exception:
|
||||
# SPA fallback
|
||||
return send_from_directory('/app/static', 'index.html')
|
||||
|
||||
|
||||
@root_bp.route('/api')
|
||||
def api_info():
|
||||
return {
|
||||
'api_version': 'v1',
|
||||
'base_url': '/api/v1',
|
||||
'endpoints': {
|
||||
'auth': '/api/v1/auth',
|
||||
'files': '/api/v1/files',
|
||||
'jobs': '/api/v1/jobs',
|
||||
'admin': '/api/v1/admin',
|
||||
'health': '/api/v1/health'
|
||||
},
|
||||
'documentation': 'Available endpoints provide RESTful API for document translation'
|
||||
}
|
||||
|
||||
|
||||
@root_bp.route('/api/health')
|
||||
def health_check():
|
||||
# Keep a simple health endpoint here for compatibility
|
||||
return {
|
||||
'status': 'healthy',
|
||||
'timestamp': datetime.utcnow().isoformat(),
|
||||
'service': 'PANJIT Document Translator API',
|
||||
'version': '1.0.0'
|
||||
}, 200
|
Reference in New Issue
Block a user