Git Product home page Git Product logo

Comments (7)

cnorthwood avatar cnorthwood commented on June 15, 2024 1

This works excellently! Thanks so much for doing the digging and getting a straightforward answer :)

from django-cra-helper.

MasterKale avatar MasterKale commented on June 15, 2024

Hmm, my initial thought is that Create-React-App has probably switched to Websockets from HTTP, causing Django to try redirecting from ws:// to http:// (hence the unexpected HTTP 301 response).

@cnorthwood Can you confirm which version of react-scripts your project is using? And if possible, can you go into your browser's Dev Tools' Network section and give me a screenshot of the Request and Response panels for that ws:// request?

from django-cra-helper.

cnorthwood avatar cnorthwood commented on June 15, 2024

I'm using react-scripts 3.4.0 (this is a new project).

Screenshot attrached (the response panel is empty)

Screenshot 2020-03-02 at 13 46 05

from django-cra-helper.

MasterKale avatar MasterKale commented on June 15, 2024

Thanks for linking that, I think your second "'Upgrade' header is missing" error response is the actual problem (which you already knew because you made the trailing slash optional to fix the 301 😛)

I poked around Create-React-App and its packages and I have an idea of what might be happening: it looks like in CRA v3.3 they update the hot reload dev server to use native Websockets instead of the sockjs-client library they were using in v3.2 and earlier. I suspect this is part of what's causing this breakage.

I also noticed that the django-proxy view I'm using to proxy this connection is stripping the Upgrade header when it proxies, which might explain the ultimate error message. This library says it's a "simple HTTP proxy" so perhaps it's no longer suitable for use in proxying ws:// URLs...

Work is nuts so I won't be able to work on this right away, but I'll definitely find time to test it out with CRA v3.4 and find a fix 😄

from django-cra-helper.

cnorthwood avatar cnorthwood commented on June 15, 2024

Thanks for looking into it :)

from django-cra-helper.

MasterKale avatar MasterKale commented on June 15, 2024

I think I've figured out how to fix this:

  1. Create an .env file in the root of your Create-React-App folder with the following environment variable:
WDS_SOCKET_PORT=3000
  1. Re-run npm start, then reload your Django view

The CRA liveserver should now connect to ws://localhost:3000 and re-enable live-reloading even from within Django:

https://giant.gfycat.com/CourteousEdibleHyrax.webm
(A screen recording showing live reloading working in Django using [email protected])

This means the following entry in urls.py is no longer required for [email protected] and up:

re_path(r'^sockjs-node/?(?P<path>.*)$', proxy_cra_requests),

@cnorthwood If you can confirm this fixes the problem on your end then I'll just need to update the README accordingly!

from django-cra-helper.

MasterKale avatar MasterKale commented on June 15, 2024

I've addressed this issue with some updates to README.md (see PR #8) highlighting the ability to use the above .env trick with current versions of create-react-app!

from django-cra-helper.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.