Commit 0ec41350 authored by Siddharth Doshi's avatar Siddharth Doshi Committed by Dan Abramov
Browse files

Use proxy for all request methods other than GET (#3726)

* Use proxy for all request methods other than GET

* Add comment
parent 91d968f9
3 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file
Showing with 8 additions and 4 deletions
+8 -4
...@@ -317,15 +317,19 @@ function prepareProxy(proxy, appPublicFolder) { ...@@ -317,15 +317,19 @@ function prepareProxy(proxy, appPublicFolder) {
// For single page apps, we generally want to fallback to /index.html. // For single page apps, we generally want to fallback to /index.html.
// However we also want to respect `proxy` for API calls. // However we also want to respect `proxy` for API calls.
// So if `proxy` is specified as a string, we need to decide which fallback to use. // So if `proxy` is specified as a string, we need to decide which fallback to use.
// We use a heuristic: if request `accept`s text/html, we pick /index.html. // We use a heuristic: We want to proxy all the requests that are not meant
// for static assets and as all the requests for static assets will be using
// `GET` method, we can proxy all non-`GET` requests.
// For `GET` requests, if request `accept`s text/html, we pick /index.html.
// Modern browsers include text/html into `accept` header when navigating. // Modern browsers include text/html into `accept` header when navigating.
// However API calls like `fetch()` won’t generally accept text/html. // However API calls like `fetch()` won’t generally accept text/html.
// If this heuristic doesn’t work well for you, use a custom `proxy` object. // If this heuristic doesn’t work well for you, use a custom `proxy` object.
context: function(pathname, req) { context: function(pathname, req) {
return ( return (
mayProxy(pathname) && req.method !== 'GET' ||
req.headers.accept && (mayProxy(pathname) &&
req.headers.accept.indexOf('text/html') === -1 req.headers.accept &&
req.headers.accept.indexOf('text/html') === -1)
); );
}, },
onProxyReq: proxyReq => { onProxyReq: proxyReq => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment