Skip to content

Commit 0ec4135

Browse files
sidoshigaearon
authored andcommitted
Use proxy for all request methods other than GET (#3726)
* Use proxy for all request methods other than GET * Add comment
1 parent 91d968f commit 0ec4135

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/react-dev-utils/WebpackDevServerUtils.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,19 @@ function prepareProxy(proxy, appPublicFolder) {
317317
// For single page apps, we generally want to fallback to /index.html.
318318
// However we also want to respect `proxy` for API calls.
319319
// So if `proxy` is specified as a string, we need to decide which fallback to use.
320-
// We use a heuristic: if request `accept`s text/html, we pick /index.html.
320+
// We use a heuristic: We want to proxy all the requests that are not meant
321+
// for static assets and as all the requests for static assets will be using
322+
// `GET` method, we can proxy all non-`GET` requests.
323+
// For `GET` requests, if request `accept`s text/html, we pick /index.html.
321324
// Modern browsers include text/html into `accept` header when navigating.
322325
// However API calls like `fetch()` won’t generally accept text/html.
323326
// If this heuristic doesn’t work well for you, use a custom `proxy` object.
324327
context: function(pathname, req) {
325328
return (
326-
mayProxy(pathname) &&
327-
req.headers.accept &&
328-
req.headers.accept.indexOf('text/html') === -1
329+
req.method !== 'GET' ||
330+
(mayProxy(pathname) &&
331+
req.headers.accept &&
332+
req.headers.accept.indexOf('text/html') === -1)
329333
);
330334
},
331335
onProxyReq: proxyReq => {

0 commit comments

Comments
 (0)