File size: 1,002 Bytes
f56e71d
 
 
c3cc0a9
f56e71d
c3cc0a9
 
 
 
 
f56e71d
 
 
c3cc0a9
 
f56e71d
 
c3cc0a9
f56e71d
 
c3cc0a9
f56e71d
 
 
 
 
 
 
 
 
 
 
c3cc0a9
f56e71d
c3cc0a9
f56e71d
 
c3cc0a9
f56e71d
 
 
 
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
import os
from flask import Flask, jsonify
from routes import api_bp, initialize_models
import logging
from datetime import datetime

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.StreamHandler()
    ]
)

def create_app():
    app = Flask(__name__)
    
    # Initialize models on startup
    initialize_models()
    
    # Register blueprints
    app.register_blueprint(api_bp, url_prefix='/api')
    
    # Home route
    @app.route('/')
    def home():
        return jsonify({
            'status': 'online',
            'timestamp': datetime.utcnow().isoformat(),
            'message': 'Welcome to the Hostel Management API'
        })
    
    return app

# This is for both local and production
app = create_app()

if __name__ == '__main__':
    # Use the port specified by Hugging Face Spaces
    port = int(os.environ.get('PORT', 7860))
    app.run(host='0.0.0.0', port=port)