5252from .types import (
5353 Accelerator ,
5454 DistInfo ,
55+ FrontendMode ,
5556 HalfstackConfig ,
5657 HostPortPair ,
5758 ImageSource ,
@@ -601,14 +602,30 @@ async def configure_webserver(self) -> None:
601602 conf_path = self .copy_config ("webserver.conf" )
602603 halfstack = self .install_info .halfstack_config
603604 service = self .install_info .service_config
605+ endpoint_protocol = self .install_variable .endpoint_protocol
606+ fqdn_prefix = self .install_variable .fqdn_prefix
607+ storage_public_address = self .install_variable .storage_public_address
608+ public_facing_address = self .install_variable .public_facing_address
604609 assert halfstack .redis_addr is not None
610+
611+ # use FQDN if provided, otherwise use public_facing_address
612+ if fqdn_prefix is not None :
613+ # With FQDN prefix, use public storage address with https
614+ wsproxy_url = f"https://{ storage_public_address } :5050"
615+ else :
616+ # Without FQDN prefix, use public_facing_address with http
617+ wsproxy_url = f"http://{ public_facing_address } :5050"
618+ # Use sed_in_place for dotted key wsproxy.url
619+ self .sed_in_place (
620+ conf_path ,
621+ re .compile (r'^wsproxy\.url\s*=\s*".*"' , flags = re .MULTILINE ),
622+ f'wsproxy.url = "{ wsproxy_url } "' ,
623+ )
624+
605625 with conf_path .open ("r" ) as fp :
606626 data = tomlkit .load (fp )
607- appproxy_itable = tomlkit .inline_table ()
608- appproxy_itable ["url" ] = (
609- f"http://{ service .appproxy_coordinator_addr .face .host } :{ service .appproxy_coordinator_addr .face .port } "
610- )
611- data ["service" ]["appproxy" ] = appproxy_itable # type: ignore
627+ if endpoint_protocol is not None :
628+ data ["service" ]["force_endpoint_protocol" ] = endpoint_protocol .value # type: ignore
612629 data ["api" ][ # type: ignore
613630 "endpoint"
614631 ] = f"http://{ service .manager_addr .face .host } :{ service .manager_addr .face .port } "
@@ -737,6 +754,14 @@ async def configure_appproxy(self) -> None:
737754 self .log .write (f"DB PORT = { halfstack .postgres_addr .face .port } " )
738755 self .log .write (f"API SECRET = { service .appproxy_api_secret } " )
739756
757+ tls_advertised = self .install_variable .tls_advertised
758+ advertised_port = self .install_variable .advertised_port
759+ wildcard_domain = self .install_variable .wildcard_domain
760+ public_facing_address = self .install_variable .public_facing_address
761+ apphub_address = self .install_variable .apphub_address
762+ app_address = self .install_variable .app_address
763+ frontend_mode = self .install_variable .frontend_mode
764+
740765 with coord_conf .open ("r" ) as fp :
741766 data = tomlkit .load (fp )
742767 data ["db" ]["type" ] = "postgresql" # type: ignore[index]
@@ -747,38 +772,90 @@ async def configure_appproxy(self) -> None:
747772 data ["db" ]["max_overflow" ] = 64 # type: ignore[index]
748773 data ["db" ]["addr" ]["host" ] = halfstack .postgres_addr .face .host # type: ignore[index]
749774 data ["db" ]["addr" ]["port" ] = halfstack .postgres_addr .face .port # type: ignore[index]
750- data ["redis" ]["host" ] = halfstack .redis_addr .face .host # type: ignore
751- data ["redis" ]["port" ] = halfstack .redis_addr .face .port # type: ignore
775+ redis_addr_table = tomlkit .inline_table ()
776+ redis_addr_table ["host" ] = halfstack .redis_addr .face .host # type: ignore
777+ redis_addr_table ["port" ] = halfstack .redis_addr .face .port # type: ignore
778+ data ["redis" ]["addr" ] = redis_addr_table # type: ignore
752779 data ["secrets" ]["api_secret" ] = service .appproxy_api_secret # type: ignore[index]
753780 data ["secrets" ]["jwt_secret" ] = service .appproxy_jwt_secret # type: ignore[index]
754- data ["permit_hash" ]["permit_hash_secret" ] = service .appproxy_permit_hash_secret # type: ignore[index]
755- data ["proxy_coordinator" ]["bind_addr" ]["host" ] = ( # type: ignore[index]
756- service .appproxy_coordinator_addr .bind .host
757- )
781+ data ["permit_hash" ]["secret" ] = service .appproxy_permit_hash_secret # type: ignore[index]
782+ data ["proxy_coordinator" ]["bind_addr" ]["host" ] = "0.0.0.0" # type: ignore[index]
758783 data ["proxy_coordinator" ]["bind_addr" ]["port" ] = ( # type: ignore[index]
759784 service .appproxy_coordinator_addr .bind .port
760785 )
786+ data ["proxy_coordinator" ]["advertised_addr" ]["host" ] = apphub_address # type: ignore[index]
787+ data ["proxy_coordinator" ]["advertised_addr" ]["port" ] = ( # type: ignore[index]
788+ service .appproxy_coordinator_addr .bind .port
789+ )
790+ if tls_advertised :
791+ data ["proxy_coordinator" ]["tls_advertised" ] = True # type: ignore[index]
792+ data ["proxy_coordinator" ]["advertised_addr" ]["port" ] = advertised_port # type: ignore[index]
761793 with coord_conf .open ("w" ) as fp :
762794 tomlkit .dump (data , fp )
763795
764796 # Worker
765797 worker_conf = self .copy_config ("app-proxy-worker.toml" )
766798 with worker_conf .open ("r" ) as fp :
767799 data = tomlkit .load (fp )
768- data ["redis" ]["host" ] = halfstack .redis_addr .face .host # type: ignore
769- data ["redis" ]["port" ] = halfstack .redis_addr .face .port # type: ignore
800+ # Update redis addr inline table
801+ redis_addr_table = tomlkit .inline_table ()
802+ redis_addr_table ["host" ] = halfstack .redis_addr .face .host # type: ignore
803+ redis_addr_table ["port" ] = halfstack .redis_addr .face .port # type: ignore
804+ data ["redis" ]["addr" ] = redis_addr_table # type: ignore
805+
770806 data ["proxy_worker" ]["coordinator_endpoint" ] = ( # type: ignore[index]
771807 f"http://{ service .appproxy_coordinator_addr .bind .host } :{ service .appproxy_coordinator_addr .bind .port } "
772808 )
773- data ["proxy_worker" ]["api_bind_addr" ] = { # type: ignore[index]
774- "host" : service .appproxy_worker_addr .bind .host ,
775- "port" : service .appproxy_worker_addr .bind .port ,
776- }
777- data ["proxy_worker" ]["port_proxy" ]["bind_port" ] = service .appproxy_worker_addr .bind .port # type: ignore[index]
778- data ["proxy_worker" ]["port_proxy" ]["bind_host" ] = service .appproxy_worker_addr .bind .host # type: ignore[index]
809+
810+ # api_bind_addr as inline table
811+ api_bind_addr_table = tomlkit .inline_table ()
812+ api_bind_addr_table ["host" ] = service .appproxy_worker_addr .bind .host
813+ api_bind_addr_table ["port" ] = service .appproxy_worker_addr .bind .port
814+ data ["proxy_worker" ]["api_bind_addr" ] = api_bind_addr_table # type: ignore[index]
815+
816+ # api_advertised_addr as inline table
817+ api_advertised_addr_table = tomlkit .inline_table ()
818+ api_advertised_addr_table ["host" ] = public_facing_address
819+ api_advertised_addr_table ["port" ] = service .appproxy_worker_addr .bind .port
820+ data ["proxy_worker" ]["api_advertised_addr" ] = api_advertised_addr_table # type: ignore[index]
821+
779822 data ["secrets" ]["api_secret" ] = service .appproxy_api_secret # type: ignore[index]
780823 data ["secrets" ]["jwt_secret" ] = service .appproxy_jwt_secret # type: ignore[index]
781- data ["permit_hash" ]["permit_hash_secret" ] = service .appproxy_permit_hash_secret # type: ignore[index]
824+ data ["permit_hash" ]["secret" ] = service .appproxy_permit_hash_secret # type: ignore[index]
825+
826+ # advertise TLS to external clients
827+ if tls_advertised :
828+ data ["proxy_worker" ]["tls_advertised" ] = True # type: ignore[index]
829+
830+ # set frontend mode (port or wildcard)
831+ data ["proxy_worker" ]["frontend_mode" ] = frontend_mode .value # type: ignore[index]
832+
833+ # configure based on frontend_mode
834+ if frontend_mode == FrontendMode .WILDCARD :
835+ # Remove port_proxy section for wildcard mode
836+ if "port_proxy" in data ["proxy_worker" ]: # type: ignore[operator]
837+ del data ["proxy_worker" ]["port_proxy" ] # type: ignore[union-attr]
838+
839+ # Override api_advertised_addr with app_address and advertised_port
840+ api_advertised_addr_table = tomlkit .inline_table ()
841+ api_advertised_addr_table ["host" ] = app_address
842+ api_advertised_addr_table ["port" ] = advertised_port
843+ data ["proxy_worker" ]["api_advertised_addr" ] = api_advertised_addr_table # type: ignore[index]
844+
845+ # Add wildcard_domain section
846+ if wildcard_domain :
847+ wildcard_table = tomlkit .table ()
848+ wildcard_table ["domain" ] = wildcard_domain
849+ bind_addr_table = tomlkit .inline_table ()
850+ bind_addr_table ["host" ] = "0.0.0.0"
851+ bind_addr_table ["port" ] = 10250
852+ wildcard_table ["bind_addr" ] = bind_addr_table
853+ wildcard_table ["advertised_port" ] = advertised_port
854+ wildcard_table .add (tomlkit .nl ()) # Add newline before next section
855+ data ["proxy_worker" ]["wildcard_domain" ] = wildcard_table # type: ignore[index]
856+ else :
857+ # update port_proxy.advertised_host
858+ data ["proxy_worker" ]["port_proxy" ]["advertised_host" ] = public_facing_address # type: ignore[index]
782859 with worker_conf .open ("w" ) as fp :
783860 tomlkit .dump (data , fp )
784861
0 commit comments