Skip to content

Commit

Permalink
Updated apiBase to use WSS if connection is established with HTTPS (#266
Browse files Browse the repository at this point in the history
)

* Updated apiBase to use WSS if connection is established with HTTPS

* move websocket apibase helper to shared class
  • Loading branch information
edsealing authored and prydonius committed Apr 24, 2018
1 parent 626bb52 commit 05a4f32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dashboard/src/components/AppView/AppView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as yaml from "js-yaml";
import * as React from "react";

import { IApp, IResource } from "../../shared/types";
import WebSocketHelper from "../../shared/WebSocketHelper";
import DeploymentStatus from "../DeploymentStatus";
import AppControls from "./AppControls";
import AppDetails from "./AppDetails";
Expand Down Expand Up @@ -59,7 +60,7 @@ class AppView extends React.Component<IAppViewProps, IAppViewState> {

const deployments = manifest.filter(d => d.kind === "Deployment");
const services = manifest.filter(d => d.kind === "Service");
const apiBase = `ws://${window.location.host}/api/kube`;
const apiBase = WebSocketHelper.apiBase();
const sockets: WebSocket[] = [];
for (const d of deployments) {
const s = new WebSocket(
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/FunctionView/FunctionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as crypto from "crypto";
import * as React from "react";

import { IDeploymentStatus, IFunction, IResource } from "../../shared/types";
import WebSocketHelper from "../../shared/WebSocketHelper";
import DeploymentStatus from "../DeploymentStatus";
import FunctionControls from "./FunctionControls";
import FunctionEditor from "./FunctionEditor";
Expand Down Expand Up @@ -48,7 +49,7 @@ class FunctionView extends React.Component<IFunctionViewProps, IFunctionViewStat
}

const f = nextProps.function;
const apiBase = `ws://${window.location.host}/api/kube`;
const apiBase = WebSocketHelper.apiBase();
const socket = new WebSocket(
`${apiBase}/apis/apps/v1beta1/namespaces/${
f.metadata.namespace
Expand Down
13 changes: 13 additions & 0 deletions dashboard/src/shared/WebSocketHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default class WebSocketHelper {
public static apiBase() {
let apiBase: string;

// Use WebSockets Secure if using HTTPS and WebSockets if not
if (location.protocol === "https:") {
apiBase = `wss://${window.location.host}/api/kube`;
} else {
apiBase = `ws://${window.location.host}/api/kube`;
}
return apiBase;
}
}

0 comments on commit 05a4f32

Please sign in to comment.