@@ -42,16 +42,27 @@ def generate_proxy_url(
4242 | TraefikWildcardDomainConfig ,
4343 protocol : str ,
4444 circuit : Circuit ,
45+ redirect_path : str | None = None ,
4546) -> str :
47+ # Generate base URL based on config type
4648 match config :
4749 case PortProxyConfig ():
48- return f"{ protocol } ://{ config .advertised_host or config .bind_host } :{ circuit .port } "
50+ base_url = f"{ protocol } ://{ config .advertised_host or config .bind_host } :{ circuit .port } "
4951 case TraefikPortProxyConfig ():
50- return f"{ protocol } ://{ config .advertised_host } :{ circuit .port } "
52+ base_url = f"{ protocol } ://{ config .advertised_host } :{ circuit .port } "
5153 case WildcardDomainConfig ():
52- return f"{ protocol } ://{ circuit .subdomain } { config .domain } :{ config .advertised_port or config .bind_addr .port } "
54+ base_url = f"{ protocol } ://{ circuit .subdomain } { config .domain } :{ config .advertised_port or config .bind_addr .port } "
5355 case TraefikWildcardDomainConfig ():
54- return f"{ protocol } ://{ circuit .subdomain } { config .domain } :{ config .advertised_port } "
56+ base_url = f"{ protocol } ://{ circuit .subdomain } { config .domain } :{ config .advertised_port } "
57+
58+ # Append redirect path if provided
59+ if redirect_path :
60+ # Ensure redirect path starts with /
61+ if not redirect_path .startswith ("/" ):
62+ redirect_path = f"/{ redirect_path } "
63+ return f"{ base_url } { redirect_path } "
64+
65+ return base_url
5566
5667
5768async def ensure_traefik_route_set_up (traefik_api_port : int , circuit : Circuit ) -> None :
@@ -148,9 +159,9 @@ async def setup(
148159 match circuit .protocol :
149160 case ProxyProtocol .HTTP :
150161 protocol = "https" if use_tls else "http"
151- response = web . HTTPPermanentRedirect (
152- generate_proxy_url (port_config , protocol , circuit ), headers = cors_headers
153- )
162+ redirect_path = jwt_body . get ( "redirect" , "" )
163+ proxy_url = generate_proxy_url (port_config , protocol , circuit , redirect_path )
164+ response = web . HTTPPermanentRedirect ( proxy_url , headers = cors_headers )
154165 cookie_domain = None
155166 if circuit .frontend_mode == FrontendMode .WILDCARD_DOMAIN :
156167 wildcard_info = config .wildcard_domain
@@ -169,7 +180,7 @@ async def setup(
169180 "directTCP" : "true" ,
170181 "auth" : params .token ,
171182 "proto" : protocol ,
172- "gateway" : generate_proxy_url (port_config , protocol , circuit ),
183+ "gateway" : generate_proxy_url (port_config , protocol , circuit , redirect_path = None ),
173184 }
174185 if jwt_body ["redirect" ]:
175186 return web .HTTPPermanentRedirect (
0 commit comments