2020-05-25 21:30:55 -05:00
|
|
|
import "babel-polyfill";
|
|
|
|
import "promise-polyfill/src/polyfill"; // polyfill Promise on IE
|
|
|
|
import "@jupyterlab/terminal/style/index.css";
|
|
|
|
import "./index.css";
|
|
|
|
import { ServerConnection } from "@jupyterlab/services";
|
|
|
|
import { JupyterLabAppFactory } from "./JupyterLabAppFactory";
|
2020-09-16 17:04:34 -07:00
|
|
|
import { Action } from "../Shared/Telemetry/TelemetryConstants";
|
|
|
|
import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor";
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
const getUrlVars = (): { [key: string]: string } => {
|
|
|
|
const vars: { [key: string]: string } = {};
|
|
|
|
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, (m, key, value): string => {
|
|
|
|
vars[key] = decodeURIComponent(value);
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
return vars;
|
|
|
|
};
|
|
|
|
|
2020-09-16 17:04:34 -07:00
|
|
|
const createServerSettings = (urlVars: { [key: string]: string }): ServerConnection.ISettings => {
|
2020-05-25 21:30:55 -05:00
|
|
|
let body: BodyInit;
|
|
|
|
if (urlVars.hasOwnProperty("terminalEndpoint")) {
|
|
|
|
body = JSON.stringify({
|
|
|
|
endpoint: urlVars["terminalEndpoint"]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const server = urlVars["server"];
|
|
|
|
let options: Partial<ServerConnection.ISettings> = {
|
|
|
|
baseUrl: server,
|
|
|
|
init: { body },
|
|
|
|
fetch: window.parent.fetch
|
|
|
|
};
|
|
|
|
if (urlVars.hasOwnProperty("token")) {
|
|
|
|
options = {
|
|
|
|
baseUrl: server,
|
|
|
|
token: urlVars["token"],
|
|
|
|
init: { body },
|
|
|
|
fetch: window.parent.fetch
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-16 17:04:34 -07:00
|
|
|
return ServerConnection.makeSettings(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
const main = async (): Promise<void> => {
|
|
|
|
const urlVars = getUrlVars();
|
|
|
|
const serverSettings = createServerSettings(urlVars);
|
|
|
|
|
|
|
|
const startTime = TelemetryProcessor.traceStart(Action.OpenTerminal, {
|
|
|
|
baseUrl: serverSettings.baseUrl
|
|
|
|
});
|
2020-09-11 23:12:28 -07:00
|
|
|
|
2020-09-16 17:04:34 -07:00
|
|
|
try {
|
|
|
|
if (urlVars.hasOwnProperty("terminal")) {
|
|
|
|
await JupyterLabAppFactory.createTerminalApp(serverSettings);
|
|
|
|
} else {
|
|
|
|
throw new Error("Only terminal is supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
TelemetryProcessor.traceSuccess(Action.OpenTerminal, startTime);
|
|
|
|
} catch (error) {
|
|
|
|
TelemetryProcessor.traceFailure(Action.OpenTerminal, startTime);
|
|
|
|
}
|
2020-05-25 21:30:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("load", main);
|