Skip to content

Commit 02b7163

Browse files
committed
add root_path if user in posit workbench
1 parent be4f6b6 commit 02b7163

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

vetiver/server.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import pandas as pd
88
import requests
99
import uvicorn
10+
import os
11+
import subprocess
1012
from fastapi import FastAPI, Request, testclient
1113
from fastapi.exceptions import RequestValidationError
1214
from fastapi.openapi.utils import get_openapi
@@ -261,7 +263,21 @@ def run(self, port: int = 8000, host: str = "127.0.0.1", **kw):
261263
>>> v_api.run() # doctest: +SKIP
262264
"""
263265
_jupyter_nb()
264-
uvicorn.run(self.app, port=port, host=host, **kw)
266+
# check to see if in Posit Workbench, pulled from FastAPI section of user guide
267+
# https://docs.posit.co/ide/server-pro/user/vs-code/guide/proxying-web-servers.html#running-fastapi-with-uvicorn # noqa
268+
if "RS_SERVER_URL" in os.environ and os.environ["RS_SERVER_URL"]:
269+
path = (
270+
subprocess.run(
271+
f"echo $(/usr/lib/rstudio-server/bin/rserver-url -l {port})",
272+
stdout=subprocess.PIPE,
273+
shell=True,
274+
)
275+
.stdout.decode()
276+
.strip()
277+
)
278+
uvicorn.run(self.app, port=port, host=host, root_path=path, **kw)
279+
else:
280+
uvicorn.run(self.app, port=port, host=host, **kw)
265281

266282
def _custom_openapi(self):
267283
import vetiver

0 commit comments

Comments
 (0)