Comments (7)
This works excellently! Thanks so much for doing the digging and getting a straightforward answer :)
from django-cra-helper.
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.
I'm using react-scripts 3.4.0 (this is a new project).
Screenshot attrached (the response panel is empty)
from django-cra-helper.
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.
Thanks for looking into it :)
from django-cra-helper.
I think I've figured out how to fix this:
- Create an .env file in the root of your Create-React-App folder with the following environment variable:
WDS_SOCKET_PORT=3000
- 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.
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)
- Missing service worker support HOT 3
- The helper doesn't seem to work when there is a "homepage" setting in package.json HOT 3
- Live reloading requests for hot-update paths fail HOT 3
- static assets from CRA not being collected HOT 2
- How to add routes from react-router-dom? HOT 1
- Webpack compile error in both Safar and Firefox latest version HOT 2
- Question on accessing images in public/ folder. HOT 2
- TypeError: can only concatenate tuple (not "list") to tuple HOT 4
- CRA over external interface dev build HOT 1
- Document that the `FileSystemFinder` needs to be in `STATICFILES_FINDERS` HOT 2
- Possibility to delete the build folder in production HOT 3
- Investigate possibility of replacing custom template tag with Django's `json_script` HOT 1
- Liveserver integration does not work with [email protected] HOT 1
- Code splitting support for live server HOT 2
- Asset loading error when CRA liveserver not found HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-cra-helper.