fromlib.providers.hooksimporthookfromlib.route_decoratorsimportpublic_route,public_routesfromstarlette.routingimportMount,Routeimportjsonprint("--- Hello from JWT mod ---")
[docs]@hook()asyncdefstartup(app,context):print('Running startup hook')print('Registering public routes:')defregister_route(route_path,route_obj):"""Helper function to register a route if it's marked as public"""ifhasattr(route_obj,'endpoint')andhasattr(route_obj.endpoint,'__public_route__'):print(f"Found public route: {route_path}")public_routes.add(route_path)returnTruereturnFalsedefprocess_routes(routes,path_prefix=""):"""Recursively process routes and sub-routes"""forrouteinroutes:ifisinstance(route,Mount):# Handle mounted sub-applicationsmount_path=path_prefix+route.path.rstrip('/')print(f"Processing mount: {mount_path}")# Process sub-routes within the mountifhasattr(route,'routes'):forsub_routeinroute.routes:ifisinstance(sub_route,Route):full_path=mount_path+sub_route.pathifnotregister_route(full_path,sub_route):print(f"Skipping private route: {full_path}")else:print(f"Skipping non-route in mount: {sub_route}")elifisinstance(route,Route):# Handle direct routesfull_path=path_prefix+route.pathifnotregister_route(full_path,route):print(f"Skipping private route: {full_path}")else:print(f"Skipping unknown route type: {route}")# Process all routesprocess_routes(app.routes)print(f"Final public routes registered: {public_routes}")