mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-03 13:14:28 +03:00
📝 added websockets doc page #2506
* Simple explanation. * Example of usage with JS. * Additional nGinx config example.
This commit is contained in:
parent
a8672e08cb
commit
286363799c
|
@ -23,6 +23,7 @@ Contents:
|
||||||
deployment-on-heroku
|
deployment-on-heroku
|
||||||
deployment-with-docker
|
deployment-with-docker
|
||||||
docker-postgres-backups
|
docker-postgres-backups
|
||||||
|
websocket
|
||||||
faq
|
faq
|
||||||
troubleshooting
|
troubleshooting
|
||||||
|
|
||||||
|
|
32
docs/websocket.rst
Normal file
32
docs/websocket.rst
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
.. _websocket:
|
||||||
|
|
||||||
|
=========
|
||||||
|
Websocket
|
||||||
|
=========
|
||||||
|
|
||||||
|
You can enable web sockets if you select ``use_async`` option when creating a project. That indicates whether the project should use web sockets with Uvicorn + Gunicorn.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
JavaScript example: ::
|
||||||
|
|
||||||
|
> ws = new WebSocket('ws://localhost:8000/') // or 'wss://<mydomain.com>/' in prod
|
||||||
|
WebSocket {url: "ws://localhost:8000/", readyState: 0, bufferedAmount: 0, onopen: null, onerror: null, …}
|
||||||
|
> ws.onmessage = event => console.log(event.data)
|
||||||
|
event => console.log(event.data)
|
||||||
|
> ws.send("ping")
|
||||||
|
undefined
|
||||||
|
pong!
|
||||||
|
|
||||||
|
If you are using nGinx instead of Traefik, you should add these lines to nGinx config: ::
|
||||||
|
|
||||||
|
location /websocket/ {
|
||||||
|
proxy_pass http://backend;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_read_timeout 86400;
|
||||||
|
}
|
||||||
|
|
||||||
|
Source: https://www.nginx.com/blog/websocket-nginx/
|
Loading…
Reference in New Issue
Block a user