@@ -101,31 +101,38 @@ async def register(self, conf: SiteConfig, acme: ACMESettings) -> None:
101101 if isinstance (conf , ServiceConfig ) and conf .router :
102102 # Handle sglang router type (1:1 service-to-router) - new implementation
103103 if conf .router .type == "sglang" :
104- # Allocate router port
105- router_port = self ._allocate_router_port ()
106- conf .router_port = router_port
107-
108- # Create per-service log directory
109- log_dir = Path (f"./router_logs/{ conf .domain } " )
110-
111- # Create router context with allocated port
112- ctx = RouterContext (
113- host = "127.0.0.1" ,
114- port = router_port ,
115- log_dir = log_dir ,
116- log_level = "info" ,
117- )
104+ # Check if router already exists for this domain
105+ if conf .domain in self ._domain_to_router :
106+ # Router already exists, reuse it
107+ router = self ._domain_to_router [conf .domain ]
108+ router_port = router .context .port
109+ conf .router_port = router_port
110+ else :
111+ # Allocate router port for new router
112+ router_port = self ._allocate_router_port ()
113+ conf .router_port = router_port
114+
115+ # Create per-service log directory
116+ log_dir = Path (f"./router_logs/{ conf .domain } " )
117+
118+ # Create router context with allocated port
119+ ctx = RouterContext (
120+ host = "127.0.0.1" ,
121+ port = router_port ,
122+ log_dir = log_dir ,
123+ log_level = "info" ,
124+ )
118125
119- # Create new router instance for this service
120- router = get_router (conf .router , context = ctx )
126+ # Create new router instance for this service
127+ router = get_router (conf .router , context = ctx )
121128
122- # Store mappings
123- self ._router_port_to_domain [router_port ] = conf .domain
124- self ._domain_to_router [conf .domain ] = router
129+ # Store mappings
130+ self ._router_port_to_domain [router_port ] = conf .domain
131+ self ._domain_to_router [conf .domain ] = router
125132
126- # Start router if not running
127- if not await run_async (router .is_running ):
128- await run_async (router .start )
133+ # Start router if not running
134+ if not await run_async (router .is_running ):
135+ await run_async (router .start )
129136
130137 # Register replicas (no model_id needed for new sglang implementation)
131138 # This allocates worker ports and returns Replica objects
0 commit comments