webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

Dev server with proxy - large JSON response causing the proxy to return only part of the json result

Open eladh opened this issue 10 years ago • 8 comments

Hi :-)

we got an issue when we running the dev server with proxy redirection (for the REST Server) in a case the response JSON is large the response sometime cut in the middle resulting Json.parse errors in the client.

we found a workaround solution disable chrome security (in dev mode only ) and send the request to the REST Server directly not via webpack dev proxy

is it issue with the node express server ? can i adjust the server to handle large JSON response ?

       // webpack dev server configuration
        devServer: {
            contentBase: "./src/main/",
            noInfo: false,
            hot: true,
            proxy: {
                '/pearl/*': 'http://localhost:9595/'
            }
        },

if need i will supply any more relevant information. 10x

eladh avatar Dec 22 '15 14:12 eladh

Got the same issue here, accessing the rest api endpoint is fine, but through the proxy, only the initial part shows up.

Might be caused by some response headers, since I don't have the issue before upgrading from PlayFramework 2.3 to 2.5.

qdrk avatar Apr 18 '16 04:04 qdrk

Its like the framework cannot handle Large JSON response. as a bypass we redirected All REST in Development mode to the Web Server.

eladh avatar Apr 18 '16 11:04 eladh

Is this still happening with 1.15.0? Note that you might need to change '/pearl/*' to '/pearl/**'

SpaceK33z avatar Aug 23 '16 16:08 SpaceK33z

I'm closing this issue because of inactivity. Feel free to comment, and we can always re-open it again.

SpaceK33z avatar Sep 08 '16 14:09 SpaceK33z

If anyone ever sees truncated json with the wds proxy if may be helpful to add this header to proxy config: headers: {"Accept-Encoding": ""}

rmanuel200 avatar Apr 21 '17 00:04 rmanuel200

Running into the same issue; headers: { "Accept-Encoding": "" } hasn't helped...

Reliably can access the local API without issues with the response. But through the proxy, responses longer than ~200 lines of JSON get cut off and thus aren't valid & cause console errors

No ideas currently for a fix

jackkoppa avatar Feb 27 '20 18:02 jackkoppa

Yay, found the fix in my case!

// Broken
devServer: {
	proxy: { /* proxy mappings */ },
	https: true,
	// other fields
}

// Fixed:
devServer: {
	proxy: { /* proxy mappings */ },
	https: true,
	http2: false,
	// other fields
}

In my case, I noticed that in the network tab was showing that, when trying to hit my local URL directly, it was HTTP 1.1

Screen Shot 2020-02-27 at 2 48 29 PM

But when trying to access the dev server endpoint, which should be proxying to that endpoint, it was HTTP 2

It appears http2 is the default for devServer, and so I needed to set to false, and I started getting the full response every time

Seems unlikely, but possibly related issue re: more consistent HTTP 2 support for devServer: #1713

jackkoppa avatar Feb 27 '20 19:02 jackkoppa

Versions: angular - v1.7.9, webpack - v4.43.0, webpack-dev-server - v3.11.0

Was receiving the following error from the AngularJS $http module: "Error: [$http:baddata] Data must be a valid JSON object. Received: ..." image

Can confirm adding http2: false to devServer fixes the issue. Cheers @jackkoppa! 🍻

Here's a snippet of my webpack devServer config:

devServer: {
    // ...
    compress: true,
    host: '0.0.0.0',
    hot: true,
    http2: false,
    https: true,
    port: 9000,
    proxy: {
      '/api': {
        target: 'http://localhost:1337',
        pathRewrite: { '^/api' : '' }
      },
      '/socket.io': {
        target: 'http://localhost:1337',
        ws: true
      }
    },
    // ...
}

benstaker avatar May 28 '20 21:05 benstaker