-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
skip Positron Proxy for fastapi and streamlit apps on PWB #5138
Conversation
I thought it was fixing something, but it turns out it's not, and actually it breaks some frameworks such as Dash.
|
||
// Preview the external URI. | ||
positron.window.previewUrl(proxyInfo.externalUri); | ||
positron.window.previewUrl(previewUri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seeM When running Fastapi in Positron on Workbench, sometimes the app url is previewed in the Viewer slightly too early, before the app server is ready. To get around this, a user can refresh the Viewer, but that is not ideal if it happens every time.
Do you have thoughts on how to get around this issue? Maybe we can ping the uri to check if it's responsive before displaying it in the Viewer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe #4276 is describing what I'm seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that uvicorn would only print the URL to stdout once the server is ready to receive connections (I haven't confirmed that). Is the delay happening at the Positron Proxy layer? If so, maybe there's something we could expose from the Positron Proxy extension i.e. an await
able or an event that we could listen to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into this a bit more and it does not seem to be in the Positron Proxy layer, as the issue still occurs even if we don't use the Positron Proxy.
For fastapi with uvicorn, we may want to wait for Application startup complete
in the terminal output before we open the app at the url. We happen to be just a little quick to open the url/slow to startup the app on Workbench, such that the fastapi app is not quite ready yet.
Perhaps this would be a separate property in the terminal/debug config for some terminal text that indicates the app is ready, before we extract the app url and view it. I'll open a separate issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #5187
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't setup a workbench dev environment so I haven't tested the changes, but code changes look good. We should try to fix the fastapi preview if possible but don't think it has to block this PR.
log.debug(`Viewing app at local uri: ${localUri} with external uri ${proxyInfo.externalUri.toString()}`); | ||
// Determine the target origin based on whether the server is running in PWB. | ||
const runningInPWB = process.env.RS_SERVER_URL ? true : false; | ||
const targetOrigin = runningInPWB ? localBaseUri : localUri; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I'm curious why the target origin differs here for workbench
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of a hack as I couldn't get UVICORN_ROOT_PATH
or --root-path
to work for fastapi in Positron Server Web or Desktop. I haven't gotten to the bottom of why it's working on Workbench.
The result on Positron Server Web without this handling is that the openapi.json
file is getting loaded from the root /openapi.json
instead of from e.g. proxy/1234/openapi.json
, so we get:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna move this PR to Draft while I try a few more things to see if we can avoid this custom handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Positron Server Web still needs this workaround. I still don't understand why the root path setting doesn't work.
I've decided to not pass fastapi through the Positron Proxy for now. I'll probably do the same for Streamlit as well.
|
||
// Preview the external URI. | ||
positron.window.previewUrl(proxyInfo.externalUri); | ||
positron.window.previewUrl(previewUri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that uvicorn would only print the URL to stdout once the server is ready to receive connections (I haven't confirmed that). Is the delay happening at the Positron Proxy layer? If so, maybe there's something we could expose from the Positron Proxy extension i.e. an await
able or an event that we could listen to here?
this allows us to run `vsce package` in the `extensions/positron-run-app` directory to generate a VSIX which can be loaded into Positron for faster extension dev iteration when running a built reh-web version of Positron.
"@types/sinon-test": "^2.4.6", | ||
"typescript": "^4.5.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows us to run vsce package
in the extensions/positron-run-app
directory to generate a VSIX, which can be loaded into Positron. This is helpful for faster extension dev iteration when running a pre-built reh-web version of Positron.
vsce package
available for that extensionQA Notes
I've been testing with the apps from https://github.com/posit-dev/qa-example-content/tree/main/workspaces/python_apps.