-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (59 loc) · 2.23 KB
/
Copy pathapp.py
File metadata and controls
78 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
ProjectCompass — Analysis catalog and execution platform.
"""
import os
from flask import Flask
from flask_apscheduler import APScheduler
from flask_cors import CORS
from basefun import ProjectCompass
from config import Config
from logging_config import setup_logging
def create_app(config_class=Config):
path = os.path.dirname(os.path.abspath(__file__)) + '/'
template_path = os.path.join(path, 'templates')
app = Flask(__name__, template_folder=template_path, static_folder=os.path.join(path, 'static'))
app.config.from_object(config_class)
# Initialize database
from models import init_db, init_fts
init_db(app)
init_fts(app)
# Security: restrict CORS
CORS(app, resources={r"/api/*": {"origins": os.environ.get('ALLOWED_ORIGINS', '*').split(',')}})
# Setup logging
setup_logging(app)
# Initialize core webapp
webapp = ProjectCompass(dir_path=path)
app.config['WEBAPP'] = webapp
# Register blueprints
from blueprints.agent import agent_bp
from blueprints.api import api_bp
from blueprints.auth import auth_bp
from blueprints.catalog import catalog_bp
from blueprints.data import data_bp
app.register_blueprint(auth_bp)
app.register_blueprint(catalog_bp)
app.register_blueprint(data_bp)
app.register_blueprint(agent_bp)
app.register_blueprint(api_bp)
# Scheduler
app.config['SCHEDULER_JOBSTORES'] = {'default': {'type': 'sqlalchemy', 'url': f'sqlite:///{path}scheduler_jobs.db'}}
app.config['SCHEDULER_API_ENABLED'] = False
scheduler = APScheduler()
scheduler.init_app(app)
scheduler.start()
app.config['SCHEDULER'] = scheduler
# Health endpoint
@app.route('/health')
def health():
from flask import jsonify
return jsonify({'status': 'ok', 'version': '0.1.0'})
# Ensure directories exist
os.makedirs(os.path.join(path, 'tmp'), exist_ok=True)
return app
# Application instance for gunicorn
app = create_app()
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
debug = os.environ.get('FLASK_DEBUG', 'False').lower() == 'true'
host = '0.0.0.0' if os.environ.get('FLASK_ENV') == 'production' else '127.0.0.1'
app.run(host=host, port=port, debug=debug)