availity-workflow icon indicating copy to clipboard operation
availity-workflow copied to clipboard

Add Logic For Rewriting URLs in JSON Response for Proxy

Open GoPro16 opened this issue 5 years ago • 5 comments

🚀 Feature request

Current Behavior

Any JSON response that comes back with contains a URL that points to the targetHost will not work if clicked via some Link component on an app because it will not be relative to localhost when developing.

Desired Behavior

The proxy should intercept the response before it reaches the UI, modify the URLs, if any exist, and then send it to the UI.

Suggested Solution

node-http-proxy-json looks to update this however, its not modifying the content-length which is why we had to revert #314

Example

With targetHost of http://www.helloworld.com

{
   "hello": "http://www.helloworld.com/test/123"
}

Should get modified to:

{
   "hello": "http://localhost:3000/test/123"
}

Once we can get the content-length updated it should work for all types of API responses.

Additional context

https://github.com/Availity/availity-workflow/pull/350

GoPro16 avatar Oct 31 '19 20:10 GoPro16

We only need to bump the version of node-http-proxy-json. Looks like the one that was used was really old.

TheSharpieOne avatar Oct 31 '19 20:10 TheSharpieOne

I suggest reverting 281a2d7f200a90 and just bumping the version of node-http-proxy-json.

TheSharpieOne avatar Oct 31 '19 20:10 TheSharpieOne

Still no dice on that

https://github.com/langjt/node-http-proxy-json/blob/master/index.js#L22-L24

https://github.com/langjt/node-http-proxy-json/issues/10

We will have to manually change the content-length on another proxyRes step before returning.

GoPro16 avatar Oct 31 '19 21:10 GoPro16

I don't see any manual change of the content-length within https://github.com/Availity/availity-workflow/blob/master/packages/workflow/scripts/proxy.js The code that you linked is the code that makes this work with newer versions of node-http-proxy-json (by removing the content-length and thus there is no mismatch)

TheSharpieOne avatar Nov 01 '19 15:11 TheSharpieOne

I think api-core may be checking the content-length match then or something is bc I tested this out via @availity/workflow@canary and it still threw that error

GoPro16 avatar Nov 01 '19 16:11 GoPro16