From 0575e85ca1ec119f07f13cdce15a8f7c5f20892f Mon Sep 17 00:00:00 2001 From: jpellizzari Date: Thu, 19 Jan 2017 16:33:45 -0800 Subject: [PATCH] Changed API URLs when running as dependency --- client/.babelrc | 2 +- client/app/scripts/utils/web-api-utils.js | 24 ++++++++++++++--------- client/package.json | 1 - scope | 0 4 files changed, 16 insertions(+), 11 deletions(-) mode change 100755 => 100644 scope diff --git a/client/.babelrc b/client/.babelrc index d0132c2fd..431d458d2 100644 --- a/client/.babelrc +++ b/client/.babelrc @@ -1,4 +1,4 @@ { - "plugins": ["lodash", "transform-export-extensions"], + "plugins": ["lodash"], "presets": ["es2015", "react"] } diff --git a/client/app/scripts/utils/web-api-utils.js b/client/app/scripts/utils/web-api-utils.js index 15c063139..e7ffbcd24 100644 --- a/client/app/scripts/utils/web-api-utils.js +++ b/client/app/scripts/utils/web-api-utils.js @@ -58,8 +58,14 @@ export function basePathSlash(urlPath) { return `${basePath(urlPath)}/`; } +const API_PATH = basePathSlash(window.location.pathname) === '/' + ? 'api' + : `/api${window.location.pathname}/api`; + const wsProto = location.protocol === 'https:' ? 'wss' : 'ws'; -const wsUrl = `${wsProto}://${location.host}${basePath(location.pathname)}`; +const wsUrl = basePathSlash(window.location.pathname) === '/' + ? `${wsProto}://${location.host}${basePath(window.location.pathname)}` + : `${wsProto}://${location.host}/api${basePath(window.location.pathname)}`; function createWebsocket(topologyUrl, optionsQuery, dispatch) { if (socket) { @@ -136,7 +142,7 @@ export function getAllNodes(getState, dispatch) { export function getTopologies(options, dispatch) { clearTimeout(topologyTimer); const optionsQuery = buildOptionsQuery(options); - const url = `api/topology?${optionsQuery}`; + const url = `${API_PATH}/topology?${optionsQuery}`; reqwest({ url, success: (res) => { @@ -171,13 +177,13 @@ export function getNodeDetails(topologyUrlsById, currentTopologyId, options, nod const obj = nodeMap.last(); if (obj && topologyUrlsById.has(obj.topologyId)) { const topologyUrl = topologyUrlsById.get(obj.topologyId); - let urlComponents = [topologyUrl, '/', encodeURIComponent(obj.id)]; + let urlComponents = [API_PATH, '/', trimStart(topologyUrl, '/api'), '/', encodeURIComponent(obj.id)]; if (currentTopologyId === obj.topologyId) { // Only forward filters for nodes in the current topology const optionsQuery = buildOptionsQuery(options); urlComponents = urlComponents.concat(['?', optionsQuery]); } - const url = urlComponents.join('').substr(1); + const url = urlComponents.join(''); reqwest({ url, @@ -204,7 +210,7 @@ export function getNodeDetails(topologyUrlsById, currentTopologyId, options, nod export function getApiDetails(dispatch) { clearTimeout(apiDetailsTimer); - const url = 'api'; + const url = API_PATH; reqwest({ url, success: (res) => { @@ -225,7 +231,7 @@ export function getApiDetails(dispatch) { export function doControlRequest(nodeId, control, dispatch) { clearTimeout(controlErrorTimer); - const url = `api/control/${encodeURIComponent(control.probeId)}/` + const url = `${API_PATH}/control/${encodeURIComponent(control.probeId)}/` + `${encodeURIComponent(control.nodeId)}/${control.id}`; reqwest({ method: 'POST', @@ -261,7 +267,7 @@ export function doControlRequest(nodeId, control, dispatch) { export function doResizeTty(pipeId, control, cols, rows) { - const url = `api/control/${encodeURIComponent(control.probeId)}/` + const url = `${API_PATH}/control/${encodeURIComponent(control.probeId)}/` + `${encodeURIComponent(control.nodeId)}/${control.id}`; return reqwest({ @@ -276,7 +282,7 @@ export function doResizeTty(pipeId, control, cols, rows) { export function deletePipe(pipeId, dispatch) { - const url = `api/pipe/${encodeURIComponent(pipeId)}`; + const url = `${API_PATH}/pipe/${encodeURIComponent(pipeId)}`; reqwest({ method: 'DELETE', url, @@ -292,7 +298,7 @@ export function deletePipe(pipeId, dispatch) { export function getPipeStatus(pipeId, dispatch) { - const url = `api/pipe/${encodeURIComponent(pipeId)}/check`; + const url = `${API_PATH}/pipe/${encodeURIComponent(pipeId)}/check`; reqwest({ method: 'GET', url, diff --git a/client/package.json b/client/package.json index 3df5cb9c6..64253ff4d 100644 --- a/client/package.json +++ b/client/package.json @@ -7,7 +7,6 @@ "private": true, "main": "index.js", "dependencies": { - "babel-plugin-transform-export-extensions": "^6.8.0", "babel-plugin-lodash": "^3.2.10", "babel-polyfill": "6.16.0", "classnames": "2.2.5", diff --git a/scope b/scope old mode 100755 new mode 100644