@@ -124,6 +124,29 @@ def sync_static_files():
124124 except Exception as e :
125125 print (f"Unexpected error during synchronization: { e } " )
126126
127+ def initialize_application ():
128+ """
129+ Initialize application: print configuration and sync static files if enabled.
130+ This runs both when started with gunicorn and when run directly with python.
131+ """
132+ print ("=" * 60 )
133+ print ("Starting API OpenCitations web application..." )
134+ print ("=" * 60 )
135+ print (f"Configuration: Base URL={ env_config ['base_url' ]} " )
136+ print (f"Sync enabled: { env_config ['sync_enabled' ]} " )
137+ print (f"Redis enabled: { env_config ['redis' ]['enabled' ]} " )
138+ print (f"Redis host: { env_config ['redis' ]['host' ]} " )
139+ print (f"SPARQL Index endpoint: { env_config ['sparql_endpoint_index' ]} " )
140+ print (f"SPARQL Meta endpoint: { env_config ['sparql_endpoint_meta' ]} " )
141+ print ("=" * 60 )
142+
143+ # Sync static files if enabled
144+ if env_config ["sync_enabled" ]:
145+ print ("Static sync is enabled (SYNC_ENABLED=true)" )
146+ sync_static_files ()
147+ else :
148+ print ("Static sync is disabled" )
149+
127150def validateAccessToken ():
128151 if not env_config ["redis" ]["enabled" ]:
129152 # If Redis is not enabled, skip token validation
@@ -413,8 +436,12 @@ def GET(self, dataset, call):
413436 "404 " , {"Content-Type" : content_type }, "No API operation found at URL '%s'" % call )
414437
415438
439+ if os .getenv ("WSGI_SERVER" ) == "gunicorn" :
440+ print ("Detected gunicorn environment (WSGI_SERVER=gunicorn)" )
441+ initialize_application ()
442+
416443
417- # Run the application
444+ # Run the application on localhost for testing/development
418445if __name__ == "__main__" :
419446 # Add startup log
420447 print ("Starting API OpenCitations web application..." )
0 commit comments