pre launch with port reservations

Date: 2025 11-November 17

That makes perfect sense. Launching services just-in-time (JIT) is often more resource-efficient.

You have two excellent, related questions here:

  1. Should I launch all ports at the start, or on-demand?

  2. Can an HTML iframe from one port be embedded into a site on a different port?


1. 🚦 Service Launch Strategy (JIT vs. Pre-launch)

If you're using the ServerManager pattern, the only technical difference between JIT and pre-launch is where you call the manager.register_server() function.

| Strategy | launch_all_services() Example | Pros | Cons |

| :--- | :--- | :--- |

| JIT (On-Demand) | Call manager.register_server(s, t) the first time a component needs the config server. | Resource-Efficient: Only consumes resources (port, memory, thread) when needed. | Latency: The user experiences a delay the first time they trigger the service while the server spins up. |

| Pre-launch (Start of App) | Call manager.register_server(s, t) immediately when the CLI starts. | Zero Latency: All services are instantly available on their fixed ports. Port Stability: Ports are secured immediately. | Resource Use: Consumes resources and locks the port even if the service is never used. |

Recommendation: Pre-launch with Port Reservation

Since you already use find_open_port and the goal is to have multiple concurrent GUIs and services, the Pre-launch strategy is usually better for user experience and system stability:


2. 🌐 IFRAME Embedding (CORS and Same-Origin Policy)

Yes, an HTML iframe from one port can be embedded into a site on a different port.

In web development, embedding content from a different origin (where the origin is defined by the combination of Protocol, Domain, and Port) is governed by the Same-Origin Policy and Cross-Origin Resource Sharing (CORS) headers.

How this works for you:

  1. Same Protocol & Domain: Both your servers run on http:// and 127.0.0.1.

  2. Different Port: Since the ports are different (8082 for the trend app, 8083 for the config app), they are considered Cross-Origin.

When the Trend App (on port 8082) loads the Config Modal (on port 8083) into an iframe:

Key Starlette/ASGI Solution: CORSMiddleware

To ensure full compatibility and allow JavaScript-based communication (if needed) and prevent the browser from blocking the content, you should add Starlette's built-in CORSMiddleware to your config_server.py application.

By doing this, you explicitly tell the browser that the Config Server trusts requests and embeddings coming from other ports on the localhost:

Python

# In src/pipeline/server/config_server.py

from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware
# ... other imports ...

# Define the middleware list
middleware = [
    Middleware(
        CORSMiddleware,
        # Allow origins from any port on localhost, or be specific: 
        # allow_origins=["http://127.0.0.1:8082"] 
        # Using '*' is simplest for local development:
        allow_origins=["*"], 
        allow_methods=["GET", "POST"],
        allow_headers=["*"],
    )
]

# Initialize Starlette app with middleware
app = Starlette(debug=True, middleware=middleware) 
# ... rest of your code ...

This configuration ensures the config_server responds with the necessary HTTP headers, allowing the Trend App to embed and interact with its content seamlessly.