Skip to content

Commit 7632b2d

Browse files
committed
frontend changes for cli
1 parent be278b5 commit 7632b2d

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

backend/services/http_server.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,19 @@ def create_fastapi_app(self, processing_service_cls=None):
7373
"""
7474
from api import ServerFastAPIRouter
7575
from fastapi import FastAPI
76+
from fastapi.middleware.cors import CORSMiddleware
7677

7778
self.fastapi_app = FastAPI(title="Clipabit Server")
79+
80+
# Add CORS middleware
81+
self.fastapi_app.add_middleware(
82+
CORSMiddleware,
83+
allow_origins=["*"],
84+
allow_credentials=True,
85+
allow_methods=["*"],
86+
allow_headers=["*"],
87+
)
88+
7889
api_router = ServerFastAPIRouter(
7990
server_instance=self,
8091
is_file_change_enabled=self.is_file_change_enabled,

frontend/streamlit/cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1+
import os
12
import subprocess
3+
import sys
24
from pathlib import Path
35

46

57
def serve() -> None:
8+
"""
9+
Serve the Streamlit frontend.
10+
11+
Usage: uv run dev <name>
12+
13+
The name parameter is required in dev mode and must match the backend
14+
dev name to connect to the correct Modal app URLs.
15+
"""
16+
env = os.environ.get("ENVIRONMENT", "dev")
17+
18+
if env == "dev":
19+
if len(sys.argv) < 2:
20+
print("Error: Name parameter is required for dev mode.")
21+
print("Usage: uv run dev <name>")
22+
print("\nExample: uv run dev john")
23+
print("This connects to the Modal app named 'john-dev-server'")
24+
sys.exit(1)
25+
26+
dev_name = sys.argv[1]
27+
os.environ["DEV_NAME"] = dev_name
28+
print(f"Starting frontend for dev instance '{dev_name}'...")
29+
630
app_path = Path(__file__).resolve().parent / "app.py"
731
subprocess.run(["streamlit", "run", str(app_path)], check=True)

frontend/streamlit/config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ class Config:
2323
if ENVIRONMENT not in ["dev", "prod", "staging"]:
2424
raise ValueError(f"Invalid ENVIRONMENT value: {ENVIRONMENT}. Must be one of: dev, prod, staging")
2525

26-
print(f"Running in {ENVIRONMENT} environment")
26+
# Dev name prefix (required in dev mode to avoid naming conflicts)
27+
DEV_NAME = os.environ.get("DEV_NAME", "")
28+
if ENVIRONMENT == "dev" and not DEV_NAME:
29+
raise ValueError(
30+
"DEV_NAME environment variable is required for dev mode. "
31+
"Run with: uv run dev <name>"
32+
)
33+
34+
print(f"Running in {ENVIRONMENT} environment" + (f" (dev instance: {DEV_NAME})" if DEV_NAME else ""))
2735

2836
# Modal app name (matches backend app name)
2937
APP_NAME = f"clipabit-{ENVIRONMENT}"
@@ -32,12 +40,14 @@ class Config:
3240
url_portion = "dev" if ENVIRONMENT == "dev" else ""
3341
url_portion2 = "-dev" if ENVIRONMENT == "dev" else ""
3442

43+
# App name prefix for dev mode (e.g., "john-dev" instead of "dev")
44+
app_prefix = f"{DEV_NAME}-{ENVIRONMENT}" if ENVIRONMENT == "dev" else ENVIRONMENT
3545

3646
# Server API URL (handles upload, status, videos, delete, cache)
37-
SERVER_BASE_URL = f"https://clipabit01--{ENVIRONMENT}-server-{url_portion}server-asgi-app{url_portion2}.modal.run"
47+
SERVER_BASE_URL = f"https://clipabit01--{app_prefix}-server-{url_portion}server-asgi-app{url_portion2}.modal.run"
3848

3949
# Search API URL (in dev its server-searchservice-asgi-app, else its search-searchservice-asgi-app)
40-
SEARCH_BASE_URL = f"https://clipabit01--{ENVIRONMENT}-{"server" if ENVIRONMENT == "dev" else "search"}-searchservice-asgi-app{url_portion2}.modal.run"
50+
SEARCH_BASE_URL = f"https://clipabit01--{app_prefix}-{"server" if ENVIRONMENT == "dev" else "search"}-searchservice-asgi-app{url_portion2}.modal.run"
4151

4252
# API Endpoints
4353
SERVER_UPLOAD_URL = f"{SERVER_BASE_URL}/upload"

0 commit comments

Comments
 (0)