#!/usr/bin/env python3 """ OpenEventDatabase Backend This is the main entry point for the OpenEventDatabase backend. It initializes the Falcon application and sets up the routes. """ import sys import falcon # Import utility modules from oedb.utils.logging import logger from oedb.utils.db import check_db_connection # Import middleware from oedb.middleware.headers import HeaderMiddleware # Import resources from oedb.resources.event import event from oedb.resources.stats import StatsResource from oedb.resources.search import EventSearch from oedb.resources.root import root from oedb.resources.demo import demo def create_app(): """ Create and configure the Falcon application. Returns: falcon.App: The configured Falcon application. """ # Create the Falcon application with middleware logger.info("Initializing Falcon application") app = falcon.App(middleware=[HeaderMiddleware()]) # Check database connection before continuing if not check_db_connection(): logger.error("Cannot start server - PostgreSQL database is not responding") sys.exit(1) # Create resource instances stats = StatsResource() event_search = EventSearch() # Add routes logger.info("Setting up API routes") app.add_route('/', root) # Handle root requests app.add_route('/event/search', event_search) # Handle event search requests app.add_route('/event/{id}', event) # Handle single event requests app.add_route('/event', event) # Handle event collection requests app.add_route('/stats', stats) # Handle stats requests app.add_route('/demo', demo) # Handle demo page requests logger.success("Application initialized successfully") return app # Create the WSGI application app = create_app() if __name__ == '__main__': # This block is executed when the script is run directly import waitress logger.info("Starting server on http://127.0.0.1:8080") waitress.serve(app, host='127.0.0.1', port=8080)