From 281a2d7f200a90a19062e4ea83ce9007c239e9cb Mon Sep 17 00:00:00 2001 From: Kyle Gray Date: Thu, 31 Oct 2019 15:59:26 -0400 Subject: [PATCH] fix(workflow): fixed bug with proxy middleware json not updating content length --- packages/workflow/package.json | 1 - packages/workflow/scripts/proxy.js | 36 ++++++++++++++++-------------- yarn.lock | 15 +------------ 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/packages/workflow/package.json b/packages/workflow/package.json index 8c78ddb6..d623f33d 100644 --- a/packages/workflow/package.json +++ b/packages/workflow/package.json @@ -71,7 +71,6 @@ "lodash.trimstart": "^4.5.1", "mini-css-extract-plugin": "^0.8.0", "moment": "^2.21.0", - "node-http-proxy-json": "^0.1.3", "node-sass": "^4.8.3", "open": "^6.4.0", "optimize-css-assets-webpack-plugin": "^5.0.1", diff --git a/packages/workflow/scripts/proxy.js b/packages/workflow/scripts/proxy.js index 93f8af63..c32e39d0 100644 --- a/packages/workflow/scripts/proxy.js +++ b/packages/workflow/scripts/proxy.js @@ -1,8 +1,6 @@ const chalk = require('chalk'); const debug = require('debug')('workflow:proxy'); const { get, merge } = require('lodash'); -const proxyJson = require('node-http-proxy-json'); -const typeIs = require('type-is'); const urlJoin = require('url-join'); const Logger = require('@availity/workflow-logger'); const escapeStringRegexp = require('escape-string-regexp'); @@ -44,7 +42,7 @@ function onRequest(proxyConfig, proxyObject) { }); } -function onResponse(proxyConfig, proxyObject, req, res) { +function onResponse(proxyConfig, proxyObject) { if (!get(proxyConfig, 'contextRewrite', true)) { return; } @@ -76,20 +74,24 @@ function onResponse(proxyConfig, proxyObject, req, res) { } }); - const isJson = typeIs.is(proxyObject.headers['content-type'], ['json']) === 'json'; - if (isJson && proxyObject.statusCode !== 304) { - proxyJson(res, proxyObject.headers['content-encoding'], body => { - if (body) { - const json = JSON.stringify(body); - const replacedUrl = regexerContext.test(json) ? hostUrl : hostUrlContext; - const replacedJson = json.replace(regexer, replacedUrl); - debug(`Rewriting response body urls to ${chalk.blue(replacedUrl)} for request ${chalk.blue(req.url)}`); - body = JSON.parse(replacedJson); - } - - return body; - }); - } + // Below code never worked as the content length also had to be modified before gzipping back to UI. + // This middleware didn't update the content length. Leaving this out unless in the future we have + // urls we want to rewrite to our localhost that isn't using ekko + + // const isJson = typeIs.is(proxyObject.headers['content-type'], ['json']) === 'json'; + // if (isJson && proxyObject.statusCode !== 304) { + // proxyJson(res, proxyObject.headers['content-encoding'], body => { + // if (body) { + // const json = JSON.stringify(body); + // const replacedUrl = regexerContext.test(json) ? hostUrl : hostUrlContext; + // const replacedJson = json.replace(regexer, replacedUrl); + // debug(`Rewriting response body urls to ${chalk.blue(replacedUrl)} for request ${chalk.blue(req.url)}`); + // body = JSON.parse(replacedJson); + // } + + // return body; + // }); + // } } function onProxyError(proxyConfiguration, err, req, res) { diff --git a/yarn.lock b/yarn.lock index a8bc4649..86d741fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4477,11 +4477,6 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" -bufferhelper@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/bufferhelper/-/bufferhelper-0.2.1.tgz#fa74a385724a58e242f04ad6646c2366f83b913e" - integrity sha1-+nSjhXJKWOJC8ErWZGwjZvg7kT4= - builtin-modules@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" @@ -5303,7 +5298,7 @@ concat-map@0.0.1: resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= -concat-stream@^1.5.0, concat-stream@^1.5.1: +concat-stream@^1.5.0: version "1.6.2" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34" integrity sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw== @@ -12968,14 +12963,6 @@ node-gyp@^5.0.2: tar "^4.4.12" which "1" -node-http-proxy-json@^0.1.3: - version "0.1.9" - resolved "https://registry.yarnpkg.com/node-http-proxy-json/-/node-http-proxy-json-0.1.9.tgz#5e744138c189ebd7e0105fe92d035a5486478cd4" - integrity sha512-WrKAR/y09BWaz5WqgbxuE6D/XsdhQFkLkSdnRk0a5uBKSINtApMV085MN7JMh+stiyBBltvgSR9SYVIZIpKKKQ== - dependencies: - bufferhelper "^0.2.1" - concat-stream "^1.5.1" - node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"