Create-react-app: configurable hostname for sockjs-node

Created on 5 Sep 2017  路  13Comments  路  Source: facebook/create-react-app

https://github.com/facebookincubator/create-react-app/blob/master/packages/react-dev-utils/webpackHotDevClient.js#L61-L69
as shown in this file there is no way to config hostname and everything about this sockjs-node ajax request. is there any reason for it that there is no configuration for it ?

I`m working on a product which is not spa. uses cookie sessions and there is no authentication token obviously. so I was in need of hot reload to. I load my react app inside the main app and for the hot reload I did change the source code of webpackHotDevClient to what I want in order to make /sockjs-node/info ajax works.
without changing this config /sockjs-node/info hits http://app.dev/sockjs-node/info but I want it to hit on http://localhost:3000/sockjs-node/info.

var connection = new SockJS(
  url.format({
    protocol: "http",
    hostname: "localhost",
    port: "3000",
    // Hardcoded in WebpackDevServer
    pathname: '/sockjs-node',
  })
);

after this change things are working fines with hot reload on

stale

Most helpful comment

react-dev-utils may be an internal package for create-react-app but i highly recommend to make it configurable. I believe that many people would use this project for reference and make their own configs, just like me :)

All 13 comments

I have the same request. @hasangilak has found the clue.

If you need to serve documents that are dynamic rendered by a backend server, meaning you would have two servers: one is your backend server, the other is webDevServer. The two servers would occupy different ports. For example, your backend server listening at 7001 and webDevServer listening at 3000. Visit your page at http://127.0.0.1:7001/index.html, then subsequent requests for hot reload stuff will also follow http://127.0.0.1:7001/. It is obvious wrong and should be http://127.0.0.1:3000/.

react-dev-utils may be an internal package for create-react-app but i highly recommend to make it configurable. I believe that many people would use this project for reference and make their own configs, just like me :)

I have the same request. it is useful for dev when developing with another server :8080 with create react own :3000 one.

+1 as above ^^ SPA is on port 3000, non SPA app which includes it is on port :8000...
Making it configurable would be great 馃憤

I fixed this problem in this PR #1994 but it never got merged, there was a lot of discussion about a better solution but I was never entirely sure what the better solution was. Would love to get this fixed.

Agreed, I referenced another what looks to be related PR that never got merged either (https://github.com/facebookincubator/create-react-app/pull/1588).

I've gone for the less than ideal temporary solution that has been suggested in this jist and run that as part of the start command https://gist.github.com/madebyherzblut/aef2377081aab39b9a780a418115d671. I know incredibly hacky, but achieves the desired effect and it is just for dev

Chiming in with my +1 for CRA to support more configuration for these types of scenarios. I know CRA takes a stance on convention > configuration, but I think providing more configuration for applications that are more than an SPA consuming an API would be a great improvement.

Much of the web is still running with server rendered content that relies on pre-loaded state, authentication, and routing handled server side, so seeing better support for those use cases would be great.

Thanks for reading.

For those use cases there are better tools like nwb. I encourage you to check them out. We can't possibly support all use cases, and intentionally focus on one: singe-page apps.

I'm building a create-react-app server-side rendering boilerplate and this functionality would be fantastic. When the server's running on port 3000 and the client on port 3001 I can't take advantage of hot-reload. The code is available here: https://github.com/lgants/create-react-app-ssr.

Also chiming with some additional support. We embed our CRA app in a separate site (different local port) by loading the bundle and it would be really helpful to have hotreloading.

Did anyone tried to configure other way around proxying API Requests or may be I have some misconception of it?

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ap13p picture ap13p  路  3Comments

fson picture fson  路  3Comments

alleroux picture alleroux  路  3Comments

Aranir picture Aranir  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments