Skip to content

Commit

Permalink
add root_path if user in posit workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelizimm committed Sep 12, 2023
1 parent be4f6b6 commit 02b7163
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion vetiver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pandas as pd
import requests
import uvicorn
import os
import subprocess
from fastapi import FastAPI, Request, testclient
from fastapi.exceptions import RequestValidationError
from fastapi.openapi.utils import get_openapi
Expand Down Expand Up @@ -261,7 +263,21 @@ def run(self, port: int = 8000, host: str = "127.0.0.1", **kw):
>>> v_api.run() # doctest: +SKIP
"""
_jupyter_nb()
uvicorn.run(self.app, port=port, host=host, **kw)
# check to see if in Posit Workbench, pulled from FastAPI section of user guide
# https://docs.posit.co/ide/server-pro/user/vs-code/guide/proxying-web-servers.html#running-fastapi-with-uvicorn # noqa
if "RS_SERVER_URL" in os.environ and os.environ["RS_SERVER_URL"]:
path = (
subprocess.run(
f"echo $(/usr/lib/rstudio-server/bin/rserver-url -l {port})",
stdout=subprocess.PIPE,
shell=True,
)
.stdout.decode()
.strip()
)
uvicorn.run(self.app, port=port, host=host, root_path=path, **kw)
else:
uvicorn.run(self.app, port=port, host=host, **kw)

def _custom_openapi(self):
import vetiver
Expand Down

0 comments on commit 02b7163

Please sign in to comment.