Repository navigation
Expand file tree
/
Copy pathapp_old.py
More file actions
79 lines (65 loc) · 2.44 KB
/
Copy pathapp_old.py
File metadata and controls
79 lines (65 loc) · 2.44 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
79
from flask import Flask, jsonify
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from config import Config
import os
def create_app(config_class=Config):
"""Application factory pattern"""
app = Flask(__name__)
app.config.from_object(config_class)
# Initialize extensions
# Configure CORS with explicit settings
CORS(app,
resources={r"/api/*": {"origins": "*"}},
supports_credentials=True,
allow_headers=["Content-Type", "Authorization"],
methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
jwt = JWTManager(app)
# Ensure upload folder exists
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
# Register blueprints
from routes.auth import auth_bp
from routes.provider import provider_bp
from routes.admin import admin_bp
from routes.customer import customer_bp
app.register_blueprint(auth_bp, url_prefix='/api/auth')
app.register_blueprint(provider_bp, url_prefix='/api/provider')
app.register_blueprint(admin_bp, url_prefix='/api/admin')
app.register_blueprint(customer_bp, url_prefix='/api/customer')
# Health check endpoint
@app.route('/api/health', methods=['GET'])
def health_check():
return jsonify({
'status': 'healthy',
'message': 'Solar Lighting Platform API is running',
'version': '1.0.0'
}), 200
# Error handlers
@app.errorhandler(404)
def not_found(error):
return jsonify({'error': 'Resource not found'}), 404
@app.errorhandler(500)
def internal_error(error):
return jsonify({'error': 'Internal server error'}), 500
@jwt.expired_token_loader
def expired_token_callback(jwt_header, jwt_payload):
return jsonify({
'error': 'Token has expired',
'message': 'Please log in again'
}), 401
@jwt.invalid_token_loader
def invalid_token_callback(error):
return jsonify({
'error': 'Invalid token',
'message': 'Please provide a valid authentication token'
}), 401
@jwt.unauthorized_loader
def missing_token_callback(error):
return jsonify({
'error': 'Authorization required',
'message': 'Please log in to access this resource'
}), 401
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=True, host='0.0.0.0', port=5000)