dunno maybe i typed in the wrong window
This commit is contained in:
parent
faeea6e4e0
commit
94aa89a97a
24
api/app.py
24
api/app.py
@ -1,21 +1,18 @@
|
||||
# api/__init__.py
|
||||
|
||||
from flask import Flask, jsonify, request
|
||||
import os
|
||||
import logging
|
||||
from neo4j import GraphDatabase
|
||||
from dotenv import load_dotenv
|
||||
from neo4j import GraphDatabase
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
import os
|
||||
import importlib.util
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app)
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Neo4j configuration
|
||||
NEO4J_URI = os.getenv("NEO4J_URI")
|
||||
NEO4J_USER = os.getenv("NEO4J_USER")
|
||||
NEO4J_PASSWORD = os.getenv("NEO4J_PASSWORD")
|
||||
@ -23,7 +20,6 @@ NEO4J_PASSWORD = os.getenv("NEO4J_PASSWORD")
|
||||
def get_driver():
|
||||
return GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))
|
||||
|
||||
# Custom logger for Neo4j queries
|
||||
neo4j_logger = logging.getLogger('Neo4jLogger')
|
||||
neo4j_logger.setLevel(logging.INFO)
|
||||
neo4j_handler = logging.StreamHandler()
|
||||
@ -31,10 +27,8 @@ neo4j_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||
neo4j_handler.setFormatter(neo4j_formatter)
|
||||
neo4j_logger.addHandler(neo4j_handler)
|
||||
|
||||
# Attach the logger to the app instance
|
||||
app.neo4j_logger = neo4j_logger
|
||||
|
||||
# Function to dynamically import and register blueprints
|
||||
def load_blueprints_from_directory(directory):
|
||||
for filename in os.listdir(directory):
|
||||
if filename.endswith('.py') and not filename.startswith('__'):
|
||||
@ -43,30 +37,22 @@ def load_blueprints_from_directory(directory):
|
||||
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
if hasattr(module, 'bp'):
|
||||
app.register_blueprint(module.bp)
|
||||
|
||||
# Load blueprints
|
||||
load_blueprints_from_directory('endpoints')
|
||||
|
||||
# Sitemap endpoint function
|
||||
@app.route('/sitemap', methods=['GET'])
|
||||
def sitemap():
|
||||
# Get all registered routes
|
||||
routes = []
|
||||
for rule in app.url_map.iter_rules():
|
||||
# Skip the sitemap route itself to avoid infinite recursion
|
||||
if rule.endpoint != 'sitemap':
|
||||
routes.append({
|
||||
'rule': rule.rule,
|
||||
'methods': list(rule.methods),
|
||||
'endpoint': rule.endpoint
|
||||
})
|
||||
|
||||
return jsonify(routes)
|
||||
|
||||
# Register the sitemap endpoint
|
||||
app.add_url_rule('/sitemap', view_func=sitemap, methods=['GET'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
Loading…
Reference in New Issue
Block a user