Skip to content
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

Add new websockets doc page #2608

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Contents:
deployment-on-heroku
deployment-with-docker
docker-postgres-backups
websocket
faq
troubleshooting

Expand Down
25 changes: 25 additions & 0 deletions docs/websocket.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _websocket:

=========
Websocket
=========

You can enable web sockets if you select ``use_async`` option when creating a project. That indicates whether the project can 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 don't use Traefik, you might have to configure your reverse proxy accordingly (example with Nginx_).

.. _Nginx: https://www.nginx.com/blog/websocket-nginx/