Skip to content

how to mount socket.io service into fastapi better? #3666

@panla

Description

@panla

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

server.py

sio_server = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*')

sio_app = socketio.ASGIApp(sio_server, socketio_path='socket.io')

app.mount('/', sio_app)
# app.mount('/ws', sio_app)

client.py

sio = socketio.Client()

sio.connect(url, namespaces='/chat', socketio_path='socket.io')

Description

if i mount like this, it can be connected

app.mount('/', sio_app)

and if i mount like this, it can`t be connected

app.mount('/ws', sio_app)

whether can mount /ws?

Fix Description

if app.mount('/ws') in server
the client need sio.connect(url, socketio_path='/ws/docket.io')

So strange

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.68

Python Version

python:3.8.11

Additional Context

python-socketio==5.4.0
websockets==9.1
uvicorn==0.14.0
fastapi==0.68.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions