-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need proxy
support
#69
Comments
nwb currenly uses its own simple Express server rather than webpack-dev-server, as I wanted the nice error overlays you get with webpack-hot-middleware but wasn't aware of a way to use it with webpack-dev-server. |
Currently I resolved with middleware, I added a |
Do we have a better solution for this requirement? I think a proxy to the API server is a common requirement for development react app. |
http-proxy-middleware can be added to For reference, here's how webpack-dev-server does this: https://github.com/webpack/webpack-dev-server/blob/658280d8c497053877aec50974766d66d9b9def1/lib/Server.js#L135 PRs are welcome, as implementing this isn't a priority for me right now (the apps I'm currently developing either serve up the API via Node.js (so I use nwb's middleware on the same server ) or will be hitting external APIs using CORS when deployed, so I don't need to proxy requests). |
@insin I have a working version of this by adding a top-level
In devServer.js the proxy path and options are simply passed to the middleware:
I can make a pull request if you think this is a good approach. Incidentally, what is your local workflow like when making changes to the nwb package? I had to keep commenting out the version check in cli.js, and I don't know if it's because I'm using yarn, but I had to build nwb, clear yarn's cache and remove and reinstall nwb using a file:/path-to-nwb each iteration. There must be a better way :) |
This looks perfectly cromulent as an initial way to add proxy support. Providing an object can act as "advanced mode", giving you complete control over proxy middleware settings. Suggestions:
Future work while I've been braining this (will create new issues for these):
For development I alias the # Bash
alias nwb="node ~/repos/nwb/lib/bin/nwb.js"
# Cmder
alias nwb=node C:\Users\Jonny\repos\nwb\lib\bin\nwb.js $* Edit: added this to CONTRIBUTING.md. |
Added #259. 1 Test fails, but it also fails locally for me when at v0.15.5. Thanks for the tips on development. I think my pain stems from having nwb local to my project instead of globally, so the alias trick didn't help when running the npm start script for my project for instance. I also tried npm link, but that also was problematic as it still runs in the context of the local nwb package, so I got errors loading autoprefixer in my postcss config. |
Is there any plan to accept #256 to master branch? |
21f57ba implements this in the |
You can now configure Webpack Dev Server for this in v0.17 |
In react app development, I usually call remote api in same domain, but the real api server runs on other process/port. So I need a proxy config like this:
The
proxy
is a webpack config, I can accesshttp://localhost:3000/api/test
to forward to my api server. Expectnwb
to support that.The text was updated successfully, but these errors were encountered: