-
Up until Starlette version 0.32.0.post1 the following code works as expected: # pip install starlette==0.32.0.post1 python-socketio
import socketio
from starlette.applications import Starlette
from starlette.responses import HTMLResponse
from starlette.routing import Route
async def homepage(_):
return HTMLResponse("""
<!DOCTYPE html>
<html>
<head>
<title>SocketIO Test</title>
<script src="https://cdn.socket.io/4.7.3/socket.io.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', (event) => {
var socket = io("/", { path: "/ws/socket.io" });
socket.on('msg', function(msg) {
document.body.innerHTML = '<h1>' + msg + '</h1>';
});
});
</script>
</head>
<body>
<h1>Connecting to SocketIO...</h1>
</body>
</html>
""")
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*')
sio_app = socketio.ASGIApp(socketio_server=sio, socketio_path='socket.io')
app = Starlette(routes=[Route("/", homepage)])
app.mount('/ws', sio_app)
@sio.on('connect')
async def handle_connect(sid, *args, **kwargs):
await sio.emit('msg', 'Hello from Starlette!') After establishing the connection the website shows "Hello from Starlette!". But when upgrading to Starlette 0.33.0 or greater, the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Looks like Starlette 0.32.0.post1 passed sio_app = socketio.ASGIApp(socketio_server=sio, socketio_path='/ws/socket.io') But why has the parameter changed in 0.33.0 and was it intentional? |
Beta Was this translation helpful? Give feedback.
0.35.1
still has the full path inscope['path']
. But as I understand from #2400 this is actually the ASGI standard. Therefore packages like fastapi-socketio, NiceGUI etc. which mount sub apps need to be adapted. Right?