@@ -206,7 +206,10 @@ def handle_all_exceptions(e):
206206
207207from flask_socketio import SocketIO
208208import services .socketio_service as socketio_service
209- socketio = SocketIO (app , cors_allowed_origins = cors_origins , async_mode = "threading" )
209+ # SocketIO doesn't support regex patterns in cors_allowed_origins, so we use "*" for dev
210+ # or explicit_allowed for production (set via ALLOWED_ORIGINS env var)
211+ socketio_cors_origins = explicit_allowed if explicit_allowed else "*"
212+ socketio = SocketIO (app , cors_allowed_origins = socketio_cors_origins , async_mode = "threading" )
210213socketio_service .socketio = socketio
211214socketio_service .register_socketio_handlers ()
212215
@@ -255,24 +258,31 @@ def handle_all_exceptions(e):
255258atexit .register (stop_retry_worker )
256259
257260if __name__ == '__main__' :
258- if not redis_client .exists ('res-canvas-draw-count' ):
259- init_count = {"id" : "res-canvas-draw-count" , "value" : 0 }
260- logger = __import__ ('logging' ).getLogger (__name__ )
261- logger .error ("Initialize res-canvas-draw-count if not present in Redis: " , init_count )
262- init_payload = {
263- "operation" : "CREATE" ,
264- "amount" : 1 ,
265- "signerPublicKey" : SIGNER_PUBLIC_KEY ,
266- "signerPrivateKey" : SIGNER_PRIVATE_KEY ,
267- "recipientPublicKey" : RECIPIENT_PUBLIC_KEY ,
268- "asset" : {
269- "data" : {
270- "id" : "res-canvas-draw-count" ,
271- "value" : 0
261+ logger = __import__ ('logging' ).getLogger (__name__ )
262+ try :
263+ if not redis_client .exists ('res-canvas-draw-count' ):
264+ init_count = {"id" : "res-canvas-draw-count" , "value" : 0 }
265+ logger .info ("Initialize res-canvas-draw-count if not present in Redis: %s" , init_count )
266+ init_payload = {
267+ "operation" : "CREATE" ,
268+ "amount" : 1 ,
269+ "signerPublicKey" : SIGNER_PUBLIC_KEY ,
270+ "signerPrivateKey" : SIGNER_PRIVATE_KEY ,
271+ "recipientPublicKey" : RECIPIENT_PUBLIC_KEY ,
272+ "asset" : {
273+ "data" : {
274+ "id" : "res-canvas-draw-count" ,
275+ "value" : 0
276+ }
272277 }
273278 }
274- }
275279
276- commit_transaction_via_graphql (init_payload )
277- redis_client .set ('res-canvas-draw-count' , 0 )
280+ try :
281+ commit_transaction_via_graphql (init_payload )
282+ except Exception as e :
283+ logger .warning ("Could not commit init transaction to GraphQL (service may be unavailable): %s" , e )
284+ redis_client .set ('res-canvas-draw-count' , 0 )
285+ except Exception as e :
286+ logger .warning ("Could not initialize draw count (Redis may be unavailable): %s" , e )
287+
278288 socketio .run (app , debug = False , host = "0.0.0.0" , port = 10010 , allow_unsafe_werkzeug = True , log_output = True )
0 commit comments