Hotfix: [FE] Remove user token from websocket

Hotfix: Remove token from mizu community #patch
Merge pull request #947 from up9inc/hotfix/Remove_token_from_community
This commit is contained in:
Igor Gov 2022-03-29 13:01:53 +03:00 committed by GitHub
commit 4a0294c61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 26 deletions

View File

@ -1,6 +1,6 @@
import React, {useEffect, useState} from "react"; import React, {useEffect, useState} from "react";
import { Button } from "@material-ui/core"; import { Button } from "@material-ui/core";
import Api,{getWebsocketUrl} from "../../../helpers/api"; import Api, { MizuWebsocketURL } from "../../../helpers/api";
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import {useSetRecoilState, useRecoilState} from "recoil"; import {useSetRecoilState, useRecoilState} from "recoil";
import {useCommonStyles} from "../../../helpers/commonStyle" import {useCommonStyles} from "../../../helpers/commonStyle"
@ -65,7 +65,7 @@ const trafficViewerApi = {...api}
return ( return (
<> <>
<TrafficViewer setAnalyzeStatus={setAnalyzeStatus} webSocketUrl={getWebsocketUrl()} isCloseWebSocket={!openWebSocket} <TrafficViewer setAnalyzeStatus={setAnalyzeStatus} webSocketUrl={MizuWebsocketURL} isCloseWebSocket={!openWebSocket}
trafficViewerApiProp={trafficViewerApi} actionButtons={actionButtons} isShowStatusBar={!openOasModal} isDemoBannerView={false}/> trafficViewerApiProp={trafficViewerApi} actionButtons={actionButtons} isShowStatusBar={!openOasModal} isDemoBannerView={false}/>
</> </>
); );

View File

@ -3,13 +3,10 @@ import * as axios from "axios";
export const MizuWebsocketURL = process.env.REACT_APP_OVERRIDE_WS_URL ? process.env.REACT_APP_OVERRIDE_WS_URL : export const MizuWebsocketURL = process.env.REACT_APP_OVERRIDE_WS_URL ? process.env.REACT_APP_OVERRIDE_WS_URL :
window.location.protocol === 'https:' ? `wss://${window.location.host}/ws` : `ws://${window.location.host}/ws`; window.location.protocol === 'https:' ? `wss://${window.location.host}/ws` : `ws://${window.location.host}/ws`;
export const FormValidationErrorType = "formError";
const CancelToken = axios.CancelToken; const CancelToken = axios.CancelToken;
const apiURL = process.env.REACT_APP_OVERRIDE_API_URL ? process.env.REACT_APP_OVERRIDE_API_URL : `${window.location.origin}/`; const apiURL = process.env.REACT_APP_OVERRIDE_API_URL ? process.env.REACT_APP_OVERRIDE_API_URL : `${window.location.origin}/`;
let token = ""
let client = null let client = null
let source = null let source = null
@ -24,8 +21,6 @@ export default class Api {
} }
constructor() { constructor() {
token = localStorage.getItem("token");
client = this.getAxiosClient(); client = this.getAxiosClient();
source = null; source = null;
} }
@ -125,20 +120,10 @@ export default class Api {
return response.data; return response.data;
} }
persistToken = (tk) => {
token = tk;
client = this.getAxiosClient();
localStorage.setItem('token', token);
}
getAxiosClient = () => { getAxiosClient = () => {
const headers = { const headers = {
Accept: "application/json" Accept: "application/json"
} }
if (token) {
headers['x-session-token'] = `${token}`; // we use `x-session-token` instead of `Authorization` because the latter is reserved by kubectl proxy, making mizu view not work
}
return axios.create({ return axios.create({
baseURL: apiURL, baseURL: apiURL,
timeout: 31000, timeout: 31000,
@ -146,12 +131,3 @@ export default class Api {
}); });
} }
} }
export function getWebsocketUrl() {
let websocketUrl = MizuWebsocketURL;
if (token) {
websocketUrl += `/${token}`;
}
return websocketUrl;
}