-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (55 loc) · 1.88 KB
/
app.py
File metadata and controls
68 lines (55 loc) · 1.88 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
from flask import Flask, jsonify
from flask_cors import CORS
from routes import api
from auth_routes import auth
from config import config
import json_storage
from env import FLASK_ENV, API_PREFIX
def create_app(config_name=None):
"""Create and configure the Flask application."""
if config_name is None:
config_name = FLASK_ENV
# Initialize Flask app
app = Flask(__name__)
# Load configuration
app.config.from_object(config[config_name])
# Initialize JSON storage
json_storage.init_storage()
# Enable CORS
CORS(app)
# Register blueprints
app.register_blueprint(api, url_prefix=API_PREFIX)
app.register_blueprint(auth, url_prefix=f'{API_PREFIX}/auth')
# Root route
@app.route('/')
def index():
return jsonify({
'name': '0xC Chat API',
'version': '1.0.0',
'description': 'A simple chat API built with Flask'
})
# Error handlers
@app.errorhandler(404)
def not_found(error):
return jsonify({
'status': 'error',
'message': 'Resource not found'
}), 404
@app.errorhandler(500)
def server_error(error):
return jsonify({
'status': 'error',
'message': 'Internal server error'
}), 500
return app
if __name__ == '__main__':
from env import HOST, PORT, FLASK_ENV
app = create_app()
# Print startup message with port information
print(f"\n🚀 0xC Chat API is starting up!")
print(f"🔌 Server running at: http://{HOST if HOST != '0.0.0.0' else 'localhost'}:{PORT}")
print(f"📚 API documentation available at: http://{HOST if HOST != '0.0.0.0' else 'localhost'}:{PORT}/")
print(f"⚙️ Using environment: {FLASK_ENV}")
print(f"🔍 Debug mode: {'enabled' if app.debug else 'disabled'}")
print(f"💬 Press CTRL+C to quit\n")
app.run(host=HOST, port=PORT)