Skip to content

[Bug]: /proxy/<port>/ does not work (at least for Streamlit and Vaadin apps) #5657

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

Closed
4 tasks done
aghasemi opened this issue Oct 17, 2022 · 10 comments
Closed
4 tasks done
Labels
waiting-for-info Waiting for more information from submitter

Comments

@aghasemi
Copy link

aghasemi commented Oct 17, 2022

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: Chrome
  • Local OS: MacOS
  • Remote OS: Ubuntu 22.04
  • Remote Architecture: x86
  • code-server --version: 4.7.1

Steps to Reproduce

  1. Clone any Streamlit or Vaadin app (possibly others?), e.g. https://github.com/aghasemi/streamlit_js_eval.
  2. Run it. Example: streamlit run example.py
  3. Vidit myCodeServer/proxy/8501

Expected

The app should run.

Actual

There is just a blank screen with Streamlit loading title.

Logs

No response

Screenshot/Video

On the server, logs look normal.

On the client (browser), if you open the JS console, you see errors in the form of

/:vendor/bokeh/bokeh-gl-2.4.3.min.js:1    
 Failed to load resource: the server responded with a status of 404 (Not Found) 

, where I believe the part with the colon is the culprit.

Is there anything else I need to do to make this work? I just followed the steps in .

Many thanks
Best

Does this issue happen in VS Code or GitHub Codespaces?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

No response

@aghasemi aghasemi added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Oct 17, 2022
@jsjoeio
Copy link
Contributor

jsjoeio commented Oct 17, 2022

Apologies, it's been a while since I've done much python. Here's what I'm doing:

  1. pip3 install streamlit_js_eval
  2. touch hello.py
  3. add this example:
import streamlit as st

st.write(f"Screen width is {streamlit_js_eval(js_expressions='screen.width', key = 'SCR')}")
  1. python3 hello.py

Output:

Traceback (most recent call last):
  File "hello.py", line 1, in <module>
    import streamlit as st
ModuleNotFoundError: No module named 'streamlit'

Though, I do know the /proxy/port is working because this works:

python3 -m http.server

image

@jsjoeio jsjoeio added waiting-for-info Waiting for more information from submitter and removed bug Something isn't working triage This issue needs to be triaged by a maintainer labels Oct 17, 2022
@aghasemi
Copy link
Author

aghasemi commented Oct 18, 2022

Sorry. You need pip3 install streamlit as well.

Given your example above, and also examples in the website which are React, VueJS, ..., can I assume that this (immensely useful) feature works only for static hosts, i.e. when your program is fully client-side?

I have also tried a Vaadin web application and failed in a similar way (i.e. URLs with :VAADIN in them not resolving).

@aghasemi aghasemi changed the title [Bug]: /proxy/<port>/ does not work [Bug]: /proxy/<port>/ does not work (at least for Streamlit and Vaadin apps) Oct 18, 2022
@jsjoeio
Copy link
Contributor

jsjoeio commented Oct 18, 2022

Sorry. You need pip3 install streamlit as well.

AH! Thank you! I'm going to blame my lack of Python knowledge and possibly my local environment but even doing that, it was not successful:

❯ pip3 install streamlit
Requirement already satisfied: streamlit in /usr/local/lib/python3.10/site-packages (1.13.0)
Requirement already satisfied: packaging>=14.1 in /usr/local/lib/python3.10/site-packages (from streamlit) (21.3)
Requirement already satisfied: cachetools>=4.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (5.2.0)
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.10/site-packages (from streamlit) (2.8.2)
Requirement already satisfied: pydeck>=0.1.dev5 in /usr/local/lib/python3.10/site-packages (from streamlit) (0.8.0b4)
Requirement already satisfied: pyarrow>=4.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (9.0.0)
Requirement already satisfied: pympler>=0.9 in /usr/local/lib/python3.10/site-packages (from streamlit) (1.0.1)
Requirement already satisfied: altair>=3.2.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (4.2.0)
Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (12.6.0)
Requirement already satisfied: blinker>=1.0.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (1.5)
Requirement already satisfied: validators>=0.2 in /usr/local/lib/python3.10/site-packages (from streamlit) (0.20.0)
Requirement already satisfied: tornado>=5.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (6.2)
Requirement already satisfied: importlib-metadata>=1.4 in /usr/local/lib/python3.10/site-packages (from streamlit) (5.0.0)
Requirement already satisfied: tzlocal>=1.1 in /usr/local/lib/python3.10/site-packages (from streamlit) (4.2)
Requirement already satisfied: protobuf!=3.20.2,<4,>=3.12 in /usr/local/lib/python3.10/site-packages (from streamlit) (3.20.3)
Requirement already satisfied: requests>=2.4 in /usr/local/lib/python3.10/site-packages (from streamlit) (2.28.1)
Requirement already satisfied: gitpython!=3.1.19 in /usr/local/lib/python3.10/site-packages (from streamlit) (3.1.29)
Requirement already satisfied: semver in /usr/local/lib/python3.10/site-packages (from streamlit) (2.13.0)
Requirement already satisfied: toml in /usr/local/lib/python3.10/site-packages (from streamlit) (0.10.2)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (9.2.0)
Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (8.1.3)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/site-packages (from streamlit) (1.23.2)
Requirement already satisfied: pandas>=0.21.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (1.4.3)
Requirement already satisfied: typing-extensions>=3.10.0.0 in /usr/local/lib/python3.10/site-packages (from streamlit) (4.3.0)
Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/site-packages (from altair>=3.2.0->streamlit) (4.16.0)
Requirement already satisfied: toolz in /usr/local/lib/python3.10/site-packages (from altair>=3.2.0->streamlit) (0.12.0)
Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/site-packages (from altair>=3.2.0->streamlit) (0.4)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/site-packages (from altair>=3.2.0->streamlit) (3.1.2)
Requirement already satisfied: gitdb<5,>=4.0.1 in /usr/local/lib/python3.10/site-packages (from gitpython!=3.1.19->streamlit) (4.0.9)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.10/site-packages (from importlib-metadata>=1.4->streamlit) (3.9.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.10/site-packages (from packaging>=14.1->streamlit) (3.0.9)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/site-packages (from pandas>=0.21.0->streamlit) (2022.2.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/site-packages (from python-dateutil->streamlit) (1.16.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/site-packages (from requests>=2.4->streamlit) (2022.6.15)
Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.10/site-packages (from requests>=2.4->streamlit) (2.1.1)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/site-packages (from requests>=2.4->streamlit) (3.3)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/site-packages (from requests>=2.4->streamlit) (1.26.12)
Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /usr/local/lib/python3.10/site-packages (from rich>=10.11.0->streamlit) (0.9.1)
Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /usr/local/lib/python3.10/site-packages (from rich>=10.11.0->streamlit) (2.13.0)
Requirement already satisfied: pytz-deprecation-shim in /usr/local/lib/python3.10/site-packages (from tzlocal>=1.1->streamlit) (0.1.0.post0)
Requirement already satisfied: decorator>=3.4.0 in /usr/local/lib/python3.10/site-packages (from validators>=0.2->streamlit) (5.1.1)
Requirement already satisfied: smmap<6,>=3.0.1 in /usr/local/lib/python3.10/site-packages (from gitdb<5,>=4.0.1->gitpython!=3.1.19->streamlit) (5.0.0)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/site-packages (from jinja2->altair>=3.2.0->streamlit) (2.1.1)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.10/site-packages (from jsonschema>=3.0->altair>=3.2.0->streamlit) (0.18.1)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.10/site-packages (from jsonschema>=3.0->altair>=3.2.0->streamlit) (22.1.0)
Requirement already satisfied: tzdata in /usr/local/lib/python3.10/site-packages (from pytz-deprecation-shim->tzlocal>=1.1->streamlit) (2022.5)

[notice] A new release of pip available: 22.2.2 -> 22.3
[notice] To update, run: /usr/local/opt/[email protected]/bin/python3.10 -m pip install --upgrade pip
Traceback (most recent call last):
  File "hello.py", line 1, in <module>
    import streamlit as st
ModuleNotFoundError: No module named 'streamlit'

It's fine though, we should be able to figure this out still.

Given your example above, and also examples in the website which are React, VueJS, ..., can I assume that this (immensely useful) feature works only for static hosts, i.e. when your program is fully client-side?

Hmm..I feel like it should work regardless of static vs dynamic host? 🤔 cc @code-asher who may know of any limitations

@aghasemi
Copy link
Author

Oops! It seems that / at the end of the URL has a critical role. Adding that somehow solved the issue of URLs containing : :")

@code-asher
Copy link
Member

Weird, I guess somehow %PUBLIC_URL% is /: when not using a trailing slash?

https://github.com/streamlit/streamlit/blob/debda4b87383a990dae3eab449ced14c8ae7f083/frontend/public/index.html#L36

It is not clear to me why PUBLIC_URL gets that value though. Glad the trailing slash sorts it out though!

@code-asher
Copy link
Member

Actually that would not explain it because PUBLIC_URL comes before /vendor. 😕

@code-asher
Copy link
Member

code-asher commented Oct 19, 2022

I was not able to reproduce the colon (it looks like it is evaluating the JS but not sure how that would happen) but for anyone curious the served HTML looks like this:

<script src="./vendor/viz/viz-1.8.0.min.js" type="javascript/worker"></script>
<script src="./vendor/bokeh/bokeh-2.4.3.min.js"></script>
<script src="./vendor/bokeh/bokeh-widgets-2.4.3.min.js"></script>
<script src="./vendor/bokeh/bokeh-tables-2.4.3.min.js"></script>
<script src="./vendor/bokeh/bokeh-api-2.4.3.min.js"></script>
<script src="./vendor/bokeh/bokeh-gl-2.4.3.min.js"></script>
<script src="./vendor/bokeh/bokeh-mathjax-2.4.3.min.js"></script>
<link href="./static/css/5.71be5c0a.chunk.css" rel="stylesheet">
<link href="./static/css/main.b46f6fce.chunk.css" rel="stylesheet">

The behavior of . in browsers depends on the trailing slash so for example if the URL is ./vendor then with /proxy/8501 that becomes /proxy/vendor (a 404) and with /proxy/8501/ that becomes /proxy/8501/vendor (works).

Ideally the application itself would check for a trailing slash and use either . or ./8501 so it works with or without a trailing slash (this is what code-server does to work at any path with or without a trailing slash) but this is pretty rare; most applications in the wild seem to depend on either a hard-coded base path or a trailing slash. (nevermind see next comment)

@code-asher
Copy link
Member

code-asher commented Oct 19, 2022

Uhh nevermind I am being dumb, a proxied application at the root would only see / in both trailing and non-trailing cases which means a trailing slash is always required at the root of a proxied application (unless the rewriting proxy itself distinguishes between a blank string and / at the root which I am not sure they do; would need to test this). The last paragraph I wrote in the previous comment only applies to the application's own sub-paths.

I guess to summarize all the noise I just put down this seems to be working as intended. 😆

@jsjoeio
Copy link
Contributor

jsjoeio commented Oct 19, 2022

Woohoo! Thanks @code-asher for diving in 🙌🏼

@aghasemi can we close this now?

@code-asher
Copy link
Member

code-asher commented Apr 29, 2024

Closing since it appears the proxy is working as it should. There is an open feature request for absproxy when hosting code-server at a base path though: #6770

@code-asher code-asher closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-info Waiting for more information from submitter
Projects
None yet
Development

No branches or pull requests

3 participants