-
Notifications
You must be signed in to change notification settings - Fork 800
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
Usage with an existing webserver #46
Comments
Hi, thank you for kind words. Have you looked at isomorphic-react-template? |
There is also isomorphic-hot-loader example. I haven't really dug into differences yet (since I'm not server-rendering myself just yet), but I think I need to document at least one of these approaches because it seems like a common issue nowadays. Does any of these solve your problem? |
I'm not terribly concerned with making the app isomorphic, but those were interesting reads, thanks. It seems all three of us are doing a variation on the same idea though. None of us are using the webpack-dev-middleware though, and I wonder if that could be used as a mounted sub-app somehow. From the looks of things, it seems proxying/redirecting is indeed the way to go. |
@sokra can you chime in to help? I wonder if there's a more proper way to do this. |
No need to proxy anything. The trick is to point Example:
The webpack/react-starter does it this way: |
I prefer to use a proxy so I can open the web app on other devices maintaining relative urls. |
Thanks for sharing the approach. |
i use a proxy as it avoids issues with cross origin resource requests. While you can and should handle cors headers for apis, browsers do not return good error information on 500 errors and using a proxy simplifies debugging during development. |
Don't know if it works uniformly (on server) but with new webpack and its new "proxy" parameter it works for me with webpack-dev-server and existing node webserver |
Not really an issue. Closing. See above for many working approaches :-). |
Before anything else, I wanted to express just how awesome I think this is.
That aside, I ran into some issues getting this to work in the kind of setup I wanted. I have an Express server that I want to use as a RESTful API and have the
/
route serve the React app. In prod, I just have it build out and serve the static assets, so there's no problem there.However, I found it a little tricky to get the hot reload working with that kind of setup in development.
I saw this section on using the webpack dev server with an existing server on the docs, and that worked well enough for basic usage, but hot reloading failed since it would try to make requests against my main server rather than the webpack one for hot reload updates.
I managed to work around this by defining a set of webpack routes to proxy through all requests for static assets.
In
/server/routes/webpack.js
, I have:and in
/server/app.js
:And this is a rough skeleton of how things are structured:
While this works, it seems like it's the wrong way to do it. I imagine this is a fairly common use-case, but I couldn't find any decent examples to support this. Is there a better approach to this than setting up a proxy like that?
The text was updated successfully, but these errors were encountered: