@@ -90,11 +90,14 @@ def handle_request(request: Request) -> Response:
9090
9191 try :
9292 function_dir = os .environ .get ("CON_DEV_DIR" , "" )
93+ logging .info ("Executing function: %s" , function_name )
9394 response = execute (function_name , body , function_dir = function_dir )
9495 except FunctionNotRegistered as e :
96+ logging .warning ("Function not found: %s" , function_name )
9597 return Response (str (e ), status = 404 )
9698
9799 if _is_error_response (response ):
100+ logging .error ("Function %s returned error response" , function_name )
98101 return Response (response , status = 500 , content_type = "application/json" )
99102
100103 return Response (response , content_type = "application/json" )
@@ -110,17 +113,24 @@ def application(environ, start_response):
110113
111114
112115def run_server ():
116+ port = int (os .environ .get ("CON_DEV_PORT" , 8000 ))
117+ if not 1 <= port <= 65535 :
118+ raise ValueError (f"Invalid port number: { port } " )
119+
120+ logging .info ("Starting development server on port %d" , port )
113121 # B104: binding to all interfaces is intentional - this is a development server
114122 run_simple (
115123 "0.0.0.0" , # nosec: B104
116- int ( os . environ . get ( "CON_DEV_PORT" , 8000 )) ,
124+ port ,
117125 create_application (),
118126 use_reloader = not bool (os .environ .get ("CON_DEV_NO_RELOAD" )),
119127 extra_files = [os .path .join (os .environ .get ("CON_DEV_DIR" , "" ), "environment.yaml" )],
120128 )
121129
122130
123131if __name__ == "__main__" :
132+ logging .basicConfig (level = logging .INFO )
133+
124134 parser = argparse .ArgumentParser ()
125135 parser .add_argument ("--dir" , type = str , help = "The directory containing the environment.yaml file" )
126136 parser .add_argument ("--secret" , type = str , help = "The secret token to use for the development server" )
@@ -136,6 +146,6 @@ def run_server():
136146 if args .port :
137147 os .environ ["CON_DEV_PORT" ] = str (args .port )
138148 if args .no_reload :
139- os .environ ["CON_DEV_NO_RELOAD" ] = "0 "
149+ os .environ ["CON_DEV_NO_RELOAD" ] = "1 "
140150
141151 run_server ()
0 commit comments