Created by: iansu
Remove "advanced proxy" object from package.json
, replace with user provided proxy.js
.
Closes #3366 (closed)
Activity
added CLA Signed label
Created by: iansu
Work in progress on new proxy.
TODO
- Figure out what exactly needs to be passed to user function to generate proxy config. Everything being passed now might not be necessary or there might be a better way to pass it (config object?)
- Possibly reload app when
proxy.js
changes (this is probably very difficult as the proxy is part of the webpack dev server config - Clean up comments and error messages
- Test various proxy configs
Created by: iansu
This is the
proxy.js
I'm using for testing:module.exports = function(paths, resolveLoopback, mayProxy, onProxyError) { let target; if (process.platform === 'win32') { target = resolveLoopback('http://localhost:8000'); } else { target = 'http://localhost:8000' } return [ { path: '/api/**/*', target, logLevel: 'silent', context: function(pathname, req) { return ( req.method !== 'GET' || (mayProxy(pathname) && req.headers.accept && req.headers.accept.indexOf('text/html') === -1) ); }, onProxyReq: proxyReq => { // Browers may send Origin headers even with same-origin // requests. To prevent CORS issues, we have to change // the Origin to match the target URL. if (proxyReq.getHeader('origin')) { proxyReq.setHeader('origin', target); } }, onError: onProxyError(target), secure: false, changeOrigin: true, ws: true, xfwd: true } ]; };
mentioned in issue #3366 (closed)
Created by: FezVrasta
I don't think this allows to proxy the root path, right?
I'd like to proxy the root path and serve the CRA from a sub directory
I have described how to make it work here:
https://github.com/facebookincubator/create-react-app/issues/3366#issuecomment-356349994Created by: yyfearth
@iansu As I commented on the #3366 (closed) I suggest to put the filename
proxy.js
into theproxy
config of the package.json. So the filename do not have to be hardcoded, and user have the freedom to chose other names.mentioned in issue #4086 (closed)