-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jtpio/server-proxy
Handle multiple servers
- Loading branch information
Showing
14 changed files
with
243 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
jupyter-config/jupyter_notebook_config.d/jupyterlab_link_share.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"NotebookApp": { | ||
"nbserver_extensions": { | ||
"jupyterlab_link_share": true | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
jupyter-config/jupyter_server_config.d/jupyterlab_link_share.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"ServerApp": { | ||
"jpserver_extensions": { | ||
"jupyterlab_link_share": true | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
from .handlers import setup_handlers | ||
from ._version import __version__ | ||
|
||
HERE = Path(__file__).parent.resolve() | ||
|
||
with (HERE / "labextension" / "package.json").open() as fid: | ||
data = json.load(fid) | ||
|
||
|
||
def _jupyter_labextension_paths(): | ||
return [{ | ||
"src": "labextension", | ||
"dest": data["name"] | ||
}] | ||
|
||
|
||
def _jupyter_server_extension_points(): | ||
return [{ | ||
"module": "jupyterlab_link_share" | ||
}] | ||
|
||
|
||
def _load_jupyter_server_extension(server_app): | ||
setup_handlers(server_app.web_app) | ||
server_app.log.info("Registered JupyterLab Link Share extension at URL path /jupyterlab_link_share") | ||
|
||
load_jupyter_server_extension = _load_jupyter_server_extension |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
|
||
import tornado | ||
|
||
from jupyter_server.base.handlers import APIHandler | ||
from jupyter_server.serverapp import list_running_servers as list_jupyter_servers | ||
from jupyter_server.utils import url_path_join | ||
from notebook.notebookapp import list_running_servers as list_notebook_servers | ||
|
||
|
||
class RouteHandler(APIHandler): | ||
@tornado.web.authenticated | ||
def get(self): | ||
servers = list(list_notebook_servers()) + list(list_jupyter_servers()) | ||
# sort by pid so PID 1 is first in Docker and Binder | ||
servers.sort(key=lambda x: x["pid"]) | ||
self.finish(json.dumps(servers)) | ||
|
||
|
||
def setup_handlers(web_app): | ||
host_pattern = ".*$" | ||
|
||
base_url = web_app.settings["base_url"] | ||
route_pattern = url_path_join(base_url, "jupyterlab_link_share", "servers") | ||
handlers = [(route_pattern, RouteHandler)] | ||
web_app.add_handlers(host_pattern, handlers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { URLExt } from '@jupyterlab/coreutils'; | ||
|
||
import { ServerConnection } from '@jupyterlab/services'; | ||
|
||
/** | ||
* Call the API extension | ||
* | ||
* @param endPoint API REST end point for the extension | ||
* @param init Initial values for the request | ||
* @returns The response body interpreted as JSON | ||
*/ | ||
export async function requestAPI<T>( | ||
endPoint = '', | ||
init: RequestInit = {} | ||
): Promise<T> { | ||
const settings = ServerConnection.makeSettings(); | ||
const requestUrl = URLExt.join( | ||
settings.baseUrl, | ||
'jupyterlab_link_share', | ||
endPoint | ||
); | ||
|
||
let response: Response; | ||
try { | ||
response = await ServerConnection.makeRequest(requestUrl, init, settings); | ||
} catch (error) { | ||
throw new ServerConnection.NetworkError(error); | ||
} | ||
|
||
let data: any = await response.text(); | ||
|
||
if (data.length > 0) { | ||
try { | ||
data = JSON.parse(data); | ||
} catch (error) { | ||
console.log('Not a JSON response body.', response); | ||
} | ||
} | ||
|
||
if (!response.ok) { | ||
throw new ServerConnection.ResponseError(response, data.message || data); | ||
} | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.