File: app.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (29 lines) | stat: -rw-r--r-- 680 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pathlib

import falcon
import falcon.asgi

from .chat import Chat
from .hub import Events
from .hub import Hub
from .ping import Pong

HERE = pathlib.Path(__file__).resolve().parent
STATIC = HERE.parent / 'static'


def create_app() -> falcon.asgi.App:
    app = falcon.asgi.App()

    # NOTE(vytas): E2E tests run Uvicorn, and the latest versions support ASGI
    #   HTTP/WSspec ver 2.4, so buffering on our side should not be needed.
    app.ws_options.max_receive_queue = 0

    hub = Hub()
    app.add_route('/ping', Pong())
    app.add_route('/sse', Events(hub))
    app.add_route('/ws/{name}', Chat(hub))

    app.add_static_route('/static', STATIC)

    return app