Skip to content

Commit

Permalink
Fix StructuredLabs#56: Modified frontend as well because it has hardc…
Browse files Browse the repository at this point in the history
…oded value
  • Loading branch information
aaryan182 committed Feb 9, 2025
1 parent bca2f32 commit bb7bf0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export default defineConfig({
},
server: {
proxy: {
"/api": "http://localhost:8501", // Forward API requests to FastAPI
"/api": {
target: `http://localhost:${process.env.PRESWALD_PORT || '8501'}`,
changeOrigin: true,
},
},
},
});
9 changes: 6 additions & 3 deletions preswald/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def init(name):

@cli.command()
@click.argument("script", default="hello.py")
@click.option("--port", default=8501, help="Port to run the server on.")
@click.option("--port", default=8501, help="Port to run the server on. Overrides port in config file if specified.")
@click.option(
"--log-level",
type=click.Choice(
Expand All @@ -82,7 +82,10 @@ def run(script, port, log_level):
"""
Run a Preswald app.
By default, it runs the `hello.py` script on localhost:8501.
Port priority:
1. --port argument (if provided)
2. port from preswald.toml (if exists)
3. default port 8501
"""
if not os.path.exists(script):
click.echo(f"Error: Script '{script}' not found. ❌")
Expand Down Expand Up @@ -160,7 +163,7 @@ def run(script, port, log_level):
default="local",
help="Target platform for deployment.",
)
@click.option("--port", default=8501, help="Port for deployment.")
@click.option("--port", default=8501, help="Port for deployment. Overrides port in config file if specified.")
@click.option(
"--log-level",
type=click.Choice(
Expand Down
3 changes: 3 additions & 0 deletions preswald/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def start_server(script: Optional[str] = None, port: int = 8501):
final_port = port if port != 8501 else (config_port if config_port is not None else 8501)
logger.info(f"Starting server on port {final_port}")

# Set environment variable for frontend
os.environ["PRESWALD_PORT"] = str(final_port)

config = uvicorn.Config(app, host="0.0.0.0", port=final_port, loop="asyncio")
server = uvicorn.Server(config)

Expand Down

0 comments on commit bb7bf0d

Please sign in to comment.