Core App changes to make it AWS compatible

This commit is contained in:
Anup Raj Gopinathan
2025-06-25 10:15:06 +02:00
parent a1694d1b75
commit b5849c7fbd
5 changed files with 37 additions and 20 deletions
+13 -10
View File
@@ -35,15 +35,17 @@ def create_app(config_class=None):
if config_class is None:
config_class = get_config()
app.config.from_object(config_class)
# Ensure SECRET_KEY is set from environment if not present
if not hasattr(config_class, 'SECRET_KEY') or not config_class.SECRET_KEY:
env_secret = os.environ.get('SECRET_KEY')
if not env_secret:
raise ValueError("SECRET_KEY environment variable is not set")
config_class.SECRET_KEY = env_secret
app.config['SECRET_KEY'] = config_class.SECRET_KEY.encode('utf-8')
# Initialize configuration
config_class.init_app(app)
# Ensure secret key is properly set
if not app.config.get('SECRET_KEY'):
raise ValueError("SECRET_KEY must be set in the configuration")
app.config['SECRET_KEY'] = app.config['SECRET_KEY'].encode('utf-8')
# Ensure instance folder exists
try:
os.makedirs(app.instance_path)
@@ -51,7 +53,8 @@ def create_app(config_class=None):
pass
# Configure logging
configure_logging(app)
if os.environ.get('HOST_ENV') != 'AWS':
configure_logging(app)
# Initialize extensions with retry logic
max_retries = 3
@@ -117,8 +120,8 @@ def create_app(config_class=None):
handler.flush()
# Debug: write all registered endpoints to a file
with open('logs/endpoints.log', 'w') as f:
for rule in app.url_map.iter_rules():
f.write(f"{rule.endpoint} {rule.methods} {rule.rule}\n")
# with open('logs/endpoints.log', 'w') as f:
# for rule in app.url_map.iter_rules():
# f.write(f"{rule.endpoint} {rule.methods} {rule.rule}\n")
return app