mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-08 12:07:06 +00:00
Initial Move from Azure DevOps to GitHub
This commit is contained in:
52
src/Terminal/index.ts
Normal file
52
src/Terminal/index.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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";
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
const main = (): void => {
|
||||
const urlVars = getUrlVars();
|
||||
console.log("URL parameters", urlVars);
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
const serverSettings = ServerConnection.makeSettings(options);
|
||||
|
||||
if (urlVars.hasOwnProperty("terminal")) {
|
||||
JupyterLabAppFactory.createTerminalApp(serverSettings);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error("Only terminal is supported");
|
||||
};
|
||||
|
||||
window.addEventListener("load", main);
|
||||
Reference in New Issue
Block a user