jupyter-server-proxy
jupyter-server-proxy copied to clipboard
Absolute URLs in HTML get 404
I have a site running in jupyterhub environment on a user's notebook that is proxied using jupyter-server-proxy on port 8080. I am facing issues with the absolute path of css and js file links in the html document. To help repro this, I created a toy website with static content, for example:
http://www.tld.com/user/johndoe/proxy/8080/index.html
The index.html code looks as follows:
<html>
<head>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<h1>Hello Heading</h1>
<p>Hello Paragraph</p>
<button>Hello Button</button>
</body>
</html>
The problem comes with resolution of style.css file path as it tries to get it at http://www.tld.com/hub/css/style.css
, which is NotFound (404).
Unfortunately, I cannot adjust the 3rd party site's absolute paths. Is there a way to root the absolute paths at http://www.tld.com/user/johndoe/proxy/8080/
instead of http://www.tld.com/hub/
? Any help would be highly appreciated.
I noticed absolute_url
in the documentation and wanted to try it. From the documentation, it seems there are two ways to specify the configuration, i.e., traitlets and python packages. I need some help getting either one of those working. Here is my code for python package (I picked the code given in the documentation and tweaked just the command section):
- Put the following code in openrefine.py
def setup_openrefine():
return {
'command': ['python', '-m', 'http.server', '8080']
}
- Created the following setup.py file:
import setuptools
setuptools.setup(
name="jupyter-openrefine-server",
# py_modules rather than packages, since we only have 1 file
py_modules=['openrefine'],
entry_points={
'jupyter_serverproxy_servers': [
# name = packagename:function_name
'openrefine = openrefine:setup_openrefine',
]
},
install_requires=['jupyter-server-proxy'],
)
-
Executed
pip install .
in the folder. -
Tried to browse
http://www.tld.com/user/johndoe/proxy/8080/
andhttp://www.tld.com/user/johndoe/openrefine
without any success.ps -aux
does not show the process running.
What am I missing?
If you're just getting started it's probably easier to use a configuration file instead of using a Python package which is useful when you've got a working application you want to distribute to others. Have you tried the example in point 4 absolute_url
of Server Process options? Put
c.ServerProxy.servers = {
'test-server': {
'command': ['python3', '-m', 'http.server', '{port}'],
'absolute_url': False
}
}
in ~/jupyter_notebook_config.py
I tried the traitlets option as well:
- put the following code in
~/.jupyter/jupyter_notebook_config.py
c.ServerProxy.servers = {
'test-server': {
'command': ['python3', '-m', 'http.server', '{port}'],
'absolute_url': False
}
}
- browsed to
http://www.tld.com/user/johndoe/test-server
and also checkedps -aux
. But don't see the command running.
I think I am missing a step to load the configuration (or python package) to trigger the command. Also, I am not sure if the endpoints I am browsing to are correct.
The first example should take effect as soon as you restart you notebook. http://www.tld.com/user/johndoe/test-server
looks like the correct URL, can you restart your notebook with debug logging?
I am running jupyterhub environment that spawns docker instance of notebook servers as a user logs in; I think that instance keeps running even when the client browser is terminated. Do I need to restart the notebook instance in the backend? Is there a way to reload the jupyter config without needing the backend access to restart the notebook. Does python package option also require restart?
Hello,
I know this is a old issue but I am facing a very similar situation with a web server that serves static files. So, I have a web server, say myapp
, that I would like to proxy using Jupyter server proxy. I have integrated it into JupyterLab and I can access it at http://localhost:8888/myapp
URL. The landing page of myapp
has say following content:
<H2>Create new session:</H2>
<FORM action="/session/new.cgi" METHOD=POST>
<INPUT NAME="NEWNAME" VALUE="Session_name">
<INPUT TYPE=SUBMIT VALUE="Create">
<br>
</FORM>
that serves static files. When I click submit
on the page, I am being redirected to http://localhost:8888/session/new.cgi
and end up with 404 error. If I manually navigate to http://localhost:8888/myapp/session/new.cgi
I can access the page without any issues. I have tried using absolute_url
, rewrite_response
without much luck. Is it possible to achieve what I am trying here? If so, any pointer would be appreciated!
Cheers!!