Add --port flag to pc run (#313)
This commit is contained in:
parent
2a5ed7d40b
commit
8068d5f176
@ -57,6 +57,7 @@ def run(
|
||||
loglevel: constants.LogLevel = typer.Option(
|
||||
constants.LogLevel.ERROR, help="The log level to use."
|
||||
),
|
||||
port: str = typer.Option(None, help="Specify a different port."),
|
||||
):
|
||||
"""Run the app in the current directory."""
|
||||
# Check that the app is initialized.
|
||||
@ -87,7 +88,7 @@ def run(
|
||||
|
||||
# Run the frontend and backend.
|
||||
if frontend:
|
||||
frontend_cmd(app.app, Path.cwd())
|
||||
frontend_cmd(app.app, Path.cwd(), port)
|
||||
if backend:
|
||||
backend_cmd(app.__name__, loglevel=loglevel)
|
||||
|
||||
@ -146,6 +147,5 @@ def export():
|
||||
|
||||
main = cli
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -48,7 +48,6 @@ if TYPE_CHECKING:
|
||||
from pynecone.event import Event, EventHandler, EventSpec
|
||||
from pynecone.var import Var
|
||||
|
||||
|
||||
# Shorthand for join.
|
||||
join = os.linesep.join
|
||||
|
||||
@ -512,12 +511,13 @@ def setup_frontend(root: Path):
|
||||
)
|
||||
|
||||
|
||||
def run_frontend(app: App, root: Path):
|
||||
def run_frontend(app: App, root: Path, port: str):
|
||||
"""Run the frontend.
|
||||
|
||||
Args:
|
||||
app: The app.
|
||||
root: root path of the project.
|
||||
port: port of the app.
|
||||
"""
|
||||
# Set up the frontend.
|
||||
setup_frontend(root)
|
||||
@ -527,7 +527,7 @@ def run_frontend(app: App, root: Path):
|
||||
|
||||
# Run the frontend in development mode.
|
||||
console.rule("[bold green]App Running")
|
||||
os.environ["PORT"] = get_config().port
|
||||
os.environ["PORT"] = get_config().port if port is None else port
|
||||
|
||||
subprocess.Popen(
|
||||
[get_package_manager(), "run", "next", "telemetry", "disable"],
|
||||
@ -542,12 +542,13 @@ def run_frontend(app: App, root: Path):
|
||||
)
|
||||
|
||||
|
||||
def run_frontend_prod(app: App, root: Path):
|
||||
def run_frontend_prod(app: App, root: Path, port: str):
|
||||
"""Run the frontend.
|
||||
|
||||
Args:
|
||||
app: The app.
|
||||
root: root path of the project.
|
||||
port: port of the app.
|
||||
"""
|
||||
# Set up the frontend.
|
||||
setup_frontend(root)
|
||||
@ -555,7 +556,7 @@ def run_frontend_prod(app: App, root: Path):
|
||||
# Export the app.
|
||||
export_app(app)
|
||||
|
||||
os.environ["PORT"] = get_config().port
|
||||
os.environ["PORT"] = get_config().port if port is None else port
|
||||
|
||||
# Run the frontend in production mode.
|
||||
subprocess.Popen(
|
||||
|
Loading…
Reference in New Issue
Block a user