diff --git a/binderhub/builder.py b/binderhub/builder.py index baf68b382..2e1580111 100644 --- a/binderhub/builder.py +++ b/binderhub/builder.py @@ -521,11 +521,22 @@ async def launch(self, kube, provider): username = launcher.unique_name_from_repo(self.repo_url) server_name = '' try: + # get file/url path, it will be passed to user_options + # this is useful when one wants to re-generate same launch url + path = self.get_argument('filepath', '').lstrip('/') + path_type = "file" if path else "" + if not path: + path = self.get_argument('urlpath', '').lstrip('/') + path_type = "url" if path else "" + app_log.info("path: %s", path) + app_log.info("path_type: %s", path_type) extra_args = { 'binder_ref_url': self.ref_url, 'binder_launch_host': self.binder_launch_host, 'binder_request': self.binder_request, 'binder_persistent_request': self.binder_persistent_request, + 'path_type': path_type, + 'path': path, } server_info = await launcher.launch(image=self.image_name, username=username, diff --git a/binderhub/launcher.py b/binderhub/launcher.py index 63810a96a..5951ae0f6 100644 --- a/binderhub/launcher.py +++ b/binderhub/launcher.py @@ -240,5 +240,9 @@ async def launch(self, image, username, server_name='', repo_url='', extra_args= format(_server_name, username, e, body)) raise web.HTTPError(500, "Failed to launch image %s" % image) - data['url'] = self.hub_url + 'user/%s/%s' % (username, server_name) - return data + # return back only what is need to launch the user server + launch_data = { + "url": self.hub_url + 'user/%s/%s' % (username, server_name), + "token": data["token"], + } + return launch_data diff --git a/binderhub/static/js/index.js b/binderhub/static/js/index.js index 8f9878d17..990f6e13e 100755 --- a/binderhub/static/js/index.js +++ b/binderhub/static/js/index.js @@ -171,7 +171,7 @@ function build(providerSpec, log, path, pathType) { $('.on-build').removeClass('hidden'); - var image = new BinderImage(providerSpec); + var image = new BinderImage(providerSpec, path, pathType); image.onStateChange('*', function(oldState, newState, data) { if (data.message !== undefined) { diff --git a/binderhub/static/js/src/image.js b/binderhub/static/js/src/image.js index f86f6a1ea..90be03d4c 100644 --- a/binderhub/static/js/src/image.js +++ b/binderhub/static/js/src/image.js @@ -1,13 +1,19 @@ var BASE_URL = $("#base-url").data().url; -export default function BinderImage(providerSpec) { +export default function BinderImage(providerSpec, path, pathType) { this.providerSpec = providerSpec; + this.path = path; + this.pathType = pathType; this.callbacks = {}; this.state = null; } BinderImage.prototype.fetch = function() { var apiUrl = BASE_URL + "build/" + this.providerSpec; + if (this.path && this.path.length > 0) { + apiUrl = apiUrl + '?' + this.pathType + 'path=' + encodeURIComponent(this.path); + } + console.log(apiUrl); this.eventSource = new EventSource(apiUrl); var that = this; this.eventSource.onerror = function(err) {