|
@@ -23,6 +23,9 @@ related to blocks, contracts, transactions, search, and the explore section, inc
|
|
|
error handlers, ensuring appropriate responses for these common HTTP errors.
|
|
error handlers, ensuring appropriate responses for these common HTTP errors.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
|
|
+import os
|
|
|
|
|
+import tomli
|
|
|
|
|
+
|
|
|
from flask import Flask, render_template
|
|
from flask import Flask, render_template
|
|
|
|
|
|
|
|
from blueprints.explore import explore_bp
|
|
from blueprints.explore import explore_bp
|
|
@@ -41,6 +44,10 @@ def create_app():
|
|
|
"""
|
|
"""
|
|
|
app = Flask(__name__)
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
+ # Load the app TOML configuration
|
|
|
|
|
+ env = os.getenv("FLASK_ENV", "localnet")
|
|
|
|
|
+ load_toml_config(app, env)
|
|
|
|
|
+
|
|
|
# Register Blueprints
|
|
# Register Blueprints
|
|
|
app.register_blueprint(explore_bp)
|
|
app.register_blueprint(explore_bp)
|
|
|
app.register_blueprint(block_bp)
|
|
app.register_blueprint(block_bp)
|
|
@@ -74,3 +81,45 @@ def create_app():
|
|
|
return render_template('500.html'), 500
|
|
return render_template('500.html'), 500
|
|
|
|
|
|
|
|
return app
|
|
return app
|
|
|
|
|
+
|
|
|
|
|
+def load_toml_config(app, env="localnet", config_path="site_config.toml"):
|
|
|
|
|
+ """
|
|
|
|
|
+ Loads environment-specific key-value pairs from a TOML configuration file into `app.config`.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ app (Flask): The Flask application.
|
|
|
|
|
+ env (str): The name of the environment section to load (default is "localnet").
|
|
|
|
|
+ config_path (str): The path to the TOML configuration file.
|
|
|
|
|
+
|
|
|
|
|
+ Raises:
|
|
|
|
|
+ FileNotFoundError: If the configuration file cannot be found.
|
|
|
|
|
+ KeyError: If the specified environment section does not exist.
|
|
|
|
|
+ """
|
|
|
|
|
+
|
|
|
|
|
+ # Verify that the configuration file exists
|
|
|
|
|
+ if not os.path.isfile(config_path):
|
|
|
|
|
+ raise FileNotFoundError(f"Configuration file '{config_path}' not found.")
|
|
|
|
|
+
|
|
|
|
|
+ # Open and parse the configuration file (TOML)
|
|
|
|
|
+ with open(config_path, "rb") as f:
|
|
|
|
|
+ config = tomli.load(f)
|
|
|
|
|
+
|
|
|
|
|
+ # Ensure the specified environment section exists in the configuration
|
|
|
|
|
+ if env not in config:
|
|
|
|
|
+ raise KeyError(f"Environment '{env}' not found in {config_path}")
|
|
|
|
|
+
|
|
|
|
|
+ # Load the environment specific configurations into the Flask app's config object
|
|
|
|
|
+ for key, value in config[env].items():
|
|
|
|
|
+ app.config[key.upper()] = value
|
|
|
|
|
+
|
|
|
|
|
+ # Print the loaded configuration for debugging or confirmation purposes
|
|
|
|
|
+ print("\n" + "=" * 40)
|
|
|
|
|
+ print("Loaded Explorer Site Configuration")
|
|
|
|
|
+ print("=" * 40)
|
|
|
|
|
+
|
|
|
|
|
+ for key in config[env]:
|
|
|
|
|
+ print(f"{key.upper()} = {app.config[key.upper()]}")
|
|
|
|
|
+
|
|
|
|
|
+ print("=" * 40 + "\n")
|
|
|
|
|
+
|
|
|
|
|
+
|