Skip to content

Commit

Permalink
Work in progress for jupyter#169
Browse files Browse the repository at this point in the history
(c) Copyright IBM Corp. 2016
  • Loading branch information
James Martin committed May 16, 2016
1 parent 01501ef commit 4d02072
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var urljoin = require('url-join');
var urlToDashboard = require('../app/url-to-dashboard');
var WsRewriter = require('../app/ws-rewriter');

var nbstore = require('../app/notebook-store');

var kgUrl = config.get('KERNEL_GATEWAY_URL');
var kgAuthToken = config.get('KG_AUTH_TOKEN');
var kgBaseUrl = config.get('KG_BASE_URL');
Expand All @@ -40,19 +42,11 @@ function initWsProxy(server) {
if (wsProxy) {
return;
}

var headers = null;
if(kgAuthToken) {
// include the kg auth token if we have one
headers = {};
headers.Authorization = 'token ' + kgAuthToken;
}

wsProxy = new WsRewriter({
server: server,
host: kgUrl,
basePath: kgBaseUrl,
headers: headers,
sessionToNbPath: function(session) {
return urlToDashboard(sessions[session]);
}
Expand Down Expand Up @@ -145,6 +139,22 @@ router.post('/kernels', bodyParser.json({ type: 'text/plain' }), function(req, r
};
}

var notebookPathHeader = req.headers['x-jupyter-notebook-path'];
var matches = notebookPathHeader.match(/^\/(?:dashboards(-plain)?)?(.*)$/);
if (!matches) {
error('Invalid notebook path header');
}else{
var notebookPath = matches[2];
var kernel_lang;
var nb = nbstore.get(notebookPath)
.then(function success(notebook){
console.log("here");
kernel_lang = notebook.metadata.kernelspec.name;
console.log(kernel_lang);
});
}
console.log(kernel_lang);

// Pass the (modified) request to the kernel gateway.
request({
url: urljoin(kgUrl, kgBaseUrl, '/api/kernels'),
Expand Down

0 comments on commit 4d02072

Please sign in to comment.